> Hey... new to the list, but didn't have time to lurk and watch the traffic,
> kind of in a bind here. I apologize in advance if I do something wrong...
> Using this code:
> <?php
>                   $link = mysql_connect()
>                       or die("Could not connect");
>                   mysql_select_db("mydb") or die("Could not select database");
>                   $result = mysql_query("SELECT * FROM cars WHERE year=1991");
>                   extract(mysql_fetch_array($result));

What is that line above for?  It's probably swallowing your first 
record. Get rid of it.
//                  while ($row = mysql_fetch_object($result)) {

Use this to avail yourself of extract correctly
                    while ($row = mysql_fetch_array($result)) {
// Not needed with extract      $generation = $row->generation;
// Not needed with extract $year = $row->year;
// Not needed with extract $owner = $row->owner;
// Not needed with extract      $email = $row->email;
// Not needed with extract $pic1 = $row->pic1;
// Not needed with extract $tmb1 = $row->tmb1;
>                               printf("<img src='%s'><br>", $pic1);
>                               printf("<small>%s</small><br>",$generation);
>                               printf("<b>%s</b><br>",$year);
>                               printf("%s<br>",$owner);
>                               printf("<a href=mailto:'%s'>%s</a><p>", $email, 
>                               printf("<a href='%s'><img src='%s' border=0></a><p>", 
>$pic1, $tmb1);
>                               }
>                   /* Free resultset */
>                   mysql_free_result($result);
>                   /* Closing connection */
>                   mysql_close($link);
> ?>
> I'm successfully able to retrieve and display information for year='1991'.
> It works great. However, if I replace '1991' with any other year that I KNOW
> there's a matching record for, I get no results. So if I were to replace
> year='1991' with year='1990', no results would be produced although the same
> query given directly in MySQL will give results. Make sense? This same
> problem happens with other fields too, it seems really selective. I can use
> WHERE color='red' and get results, but color='black' returns nothing,
> although there are matching records. Taking out the WHERE in the above code
> will return all but the first record in the table. I fixed that just by
> putting a dummy record first, but that still shouldn't be happening.
> Any ideas? I need to get this fixed but I'm not sure what's wrong!

Try the mods above; make sure that you quote the year value if the year 
field is text, and perhaps stick in a mysql_error after your query to see 
if any eror is coming back from mysql.

Is there any chance that you have stray white space in your year fields? 
If year is a char type and SELECT * FROM cars WHERE year LIKE '%1990%' 
works, you likely have stray junk in your db.

David Robley
Temporary Kiwi!

Quod subigo farinam

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to