silvrfoxx Posted January 9, 2009 Share Posted January 9, 2009 I have been working on one of my sites updating it to php w/ mySQL and so I am pretty new and mostly self taught on the php part. I am having trouble when I am running my script that I am getting the all of the information in my tables to display great, but the WHERE part of my mySQL script doesn't seem to be narrowing down the results, it is displaying everything. Please help me figure out what I have wrong, plus any advise on things I am missing would help too. Thanks. <table> <? $result = mysql_query("SELECT * FROM table WHERE Genre = 'action'"); while ($result_rows = mysql_fetch_array($result)) { ?> <tr> <td align="center" valign="middle"> <p><a href="index.php?action=<? echo $result_rows[Link] ?>"><? echo $result_rows[Name] ?></a></p> <p><a href="index.php?action=<? echo $result_rows[Link] ?>"><img src="images/<? echo $result_rows[image] ?>" alt="<? echo $result_rows[Name] ?>" width="70" height="70"></a></p> </td> <? $result_rows = mysql_fetch_array($result); if ($result_rows > 0) { ?> <td align="center" valign="middle"> <p><a href="index.php?action=<? echo $result_rows[Link] ?>"><? echo $result_rows[Name] ?></a></p> <p><a href="index.php?action=<? echo $result_rows[Link] ?>"><img src="images/<? echo $result_rows[image] ?>" alt="<? echo $result_rows[Name] ?>" width="70" height="70"></a></p> </td> <? } else { ?> <td align="center" valign="middle"></td> <? } $result_rows = mysql_fetch_array($result); if ($result_rows > 0) { ?> <td align="center" valign="middle"> <p><a href="index.php?action=<? echo $result_rows[Link] ?>"><? echo $result_rows[Name] ?></a></p> <p><a href="index.php?action=<? echo $result_rows[Link] ?>"><img src="images/<? echo $result_rows[image] ?>" alt="<? echo $result_rows[Name] ?>" width="70" height="70"></a></p> </td> <? } else { ?> <td align="center" valign="middle"></td> <? } $result_rows = mysql_fetch_array($result); if ($result_rows > 0) { ?> <td align="center" valign="middle"> <p><a href="index.php?action=<? echo $result_rows[Link] ?>"><? echo $result_rows[Name] ?></a></p> <p><a href="index.php?action=<? echo $result_rows[Link] ?>"><img src="images/<? echo $result_rows[image] ?>" alt="<? echo $result_rows[Name] ?>" width="70" height="70"></a></p> </td> </tr> <? } else { ?> <td align="center" valign="middle"></td> </tr> <? } } ?> </table> Quote Link to comment Share on other sites More sharing options...
studgate Posted January 9, 2009 Share Posted January 9, 2009 Where is the action in the WHERE statement comes from, if you took it from the url, you should try $_GET['action'] try: $result = mysql_query("SELECT * FROM table WHERE Genre = '$_GET['action']'"); Quote Link to comment Share on other sites More sharing options...
silvrfoxx Posted January 9, 2009 Author Share Posted January 9, 2009 the action in the WHERE statement is coming from the Genre column in the table. The table is already built out and has Genre, Link, Name, etc. There is nothing needed from the url. Quote Link to comment Share on other sites More sharing options...
xtopolis Posted January 10, 2009 Share Posted January 10, 2009 SELECT * FROM table WHERE Genre = 'action'; If you run this query in your mysql console or PHPmyadmin, does it return the expected results? Also you are overwriting $result_rows each time, so it looks like it would be display the first row returned over and over? Quote Link to comment Share on other sites More sharing options...
silvrfoxx Posted January 10, 2009 Author Share Posted January 10, 2009 When i run the query in PHPmyadmin it does return the expected results. When the code is run it isn't displaying the first row over and over, it is displaying all of rows in the database. Which is undesired because I am wanting to just narrow it down to those with the Genre of action. The reason for the $result_rows over and over again is to reaccess the database for the next row. I have to do this because I am wanting to display the page with a row of 4 items then go to the next row (the <tr> is at the beginning then there are 4 <td> and then the </tr>) Quote Link to comment Share on other sites More sharing options...
xtopolis Posted January 10, 2009 Share Posted January 10, 2009 Well, if you say mysql is return this right result, then you should test the PHP is receiving... Debug by looking at the first part of your script: $result = mysql_query("SELECT * FROM table WHERE Genre = 'action'"); while ($result_rows = mysql_fetch_array($result)) { echo $result_rows[Name].'<br />'; } And make sure that it returns the same data. From there if it does, then it just comes down to an error displaying it. You can probably use a modulus operator to make it echo a new row after 4 columns. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.