Jump to content

My WHERE piece isn't working


silvrfoxx

Recommended Posts

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.