Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

missing rows

Codes here !

Moderators: macek, egami, gesf

missing rows

Postby tranquillo » Wed Jan 15, 2003 5:16 pm

hey... I must be doing something wrong... I just don't know what... to me it don't seem logical at all... the code that is pressented below is to list gigs for a couple of musicians... it's ordered by date and for some reason it refuses to show one of the rows... why? it's just one.

---------------------------------------

$result2 = mysql_query("SELECT * FROM spelningar where spelningar.datum >= current_date AND
spelningar.artist='wieskahubert' order by datum",$db);

---------------------------------------


if ($myrow = mysql_fetch_array($result2)) {

do {
echo "<table width='270' border='0' cellpadding='0' cellspacing='0' class='textsmall' bgcolor=\n";
echo ($var%2) ? "'#CCCCCC'><tr><td align='left'>" : "'#FFFFFF'><tr><td align='left'>";
$var++;

printf("%s</td><td align='left' width='120'>%s</td><td align='left' width='60'>%s",
$myrow["datum"], $myrow["plats"], $myrow["land"]);

echo "</td><td></td></tr></table>\n";

} while ($myrow = mysql_fetch_array($result2));
} else {
echo "Sorry, no records were found!";
}

----------------------------------------------

if I write the SQL queary directly to the MySQL there's no problem. so there's nothing wrong with the dates...

thanks...

-s
tranquillo
New php-forum User
New php-forum User
 
Posts: 74
Joined: Sun Nov 24, 2002 6:48 pm
Location: katrineholm

Postby Joan Garnet » Sat Jan 18, 2003 5:25 am

Try this one:
Code: Select all
$my_count = mysql_num_rows($result2);
if ( $my_count != 0 ){
   while ($myrow = mysql_fetch_array($result2)){
      echo "<table width='270' border='0' cellpadding='0' cellspacing='0' class='textsmall' bgcolor=\n";
      echo ($var%2) ? "'#CCCCCC'><tr><td align='left'>" : "'#FFFFFF'><tr><td align='left'>";
      $var++;
      printf("%s</td><td align='left' width='120'>%s</td><td align='left' width='60'>%s",
      $myrow["datum"], $myrow["plats"], $myrow["land"]);
      echo "</td><td></td></tr></table>\n";
   }
}else{
   echo "Sorry, no records were found!";
}


As you see there's no need to call mysql_fetch_array so many times.
bye!
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Postby tranquillo » Sat Jan 18, 2003 8:42 am

thanks... but that code did exactly the same thing as mine... it ignores one row... it lists every row except one where the date is 20030125. there are thre different lists. one with upcoming concerts one with previous concerts and one with concerts with another artist. it's just one of the lists that does that. and the code is the same on all of them. the only thing that's different is the query it's connected to...

---------------
$result = mysql_query("SELECT * FROM spelningar where spelningar.artist='wieska' order by datum",$db);
$result2 = mysql_query("SELECT * FROM spelningar where spelningar.datum <= current_date AND
spelningar.artist='wieskahubert' order by datum",$db);
$result3 = mysql_query("SELECT * FROM spelningar where spelningar.datum >= current_date AND
spelningar.artist='wieskahubert' order by datum",$db);
---------------
the three lists are placed in three layers that look exactly the same. and it's in layer2 that everything gets messed up... it doesn't mattar which code I put there, it cuts the first row. and I know for sure that the layer is the same as the rest (ctrl+c/ctrl+v) ;)


thanks...
tranquillo
New php-forum User
New php-forum User
 
Posts: 74
Joined: Sun Nov 24, 2002 6:48 pm
Location: katrineholm

Postby Joan Garnet » Sat Jan 18, 2003 3:37 pm

Why are you using <= ???
Explain the code a little bit.
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Postby tranquillo » Sun Jan 19, 2003 5:36 am

it's a list of upcoming and previous concerts. the sql query is basicly show the date and the place from table where the date is before or exactly today. and the sql query for the upcoming table is show the date and the place from table where the date is later or exactly today.
tranquillo
New php-forum User
New php-forum User
 
Posts: 74
Joined: Sun Nov 24, 2002 6:48 pm
Location: katrineholm

Postby tranquillo » Sun Jan 19, 2003 5:41 am

by the way... do you know how to change the format of the date? now it shows 2003-01-01 and I want it to show jan 2003 or jan -03 for the previous concerts.
tranquillo
New php-forum User
New php-forum User
 
Posts: 74
Joined: Sun Nov 24, 2002 6:48 pm
Location: katrineholm

Postby Joan Garnet » Sun Jan 19, 2003 9:29 am

Use this:
Code: Select all
$sql_date = mysql_query("SELECT date_format(date_column, '%M %D, %Y') as date FROM table WHERE id='$someid'") or die (mysql_error());

while(list($date)=mysql_fetch_row($sql_date)){
echo "The date of this row is: $date";
}


More info:
http://www.phpfreaks.com/mysqlref/3.php
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars


Return to mySQL & php coding

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.