Beat_88 Posted November 20, 2007 Share Posted November 20, 2007 I have done this PHP code for my site. And the script is for game reviews and I want to have so that if you click on the button Xbox 360 then only reviews for Xbox 360 get shown. I have done this script but I cant get it to work. Whan I click on the button I get this message. "Message" Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\Wamp\wamp\www\databas\sa\recensionsindex.php on line 105. If I write in the my query WHERE format ='Xbox 360' then it works. Here is my PHP code: <?php $result = mysql_query("SELECT count(*) as count FROM game $where"); $fetch = mysql_fetch_assoc($result); $allNews = $fetch['count']; $newsPerPage = 5; $maxPages = (int)($allNews/$newsPerPage)+1; $page = $_GET['page']; // $page = 2; if($page<1 || $page>$maxPages || !is_numeric($page)) { $page = 1; } $start = ($page-1)*$newsPerPage; $limit = "LIMIT $start,$newsPerPage"; ?> <?php $where = ""; if (!isSet($_GET["type"])) { //Du valde "Alla" i menyn $where = ""; //kan vara ett blankt alternativ också, men du vill //fånga detta fall för att veta att type är satt nedan, //annars kan du få problem. } else if ($_GET["type"] == 1) $where =" format = 'PC'"; else if ($_GET["type"] == 2) $where = " format = 'PS 2' "; else if ($_GET["type"] == 3) $where = " format = 'PS 3' "; else if ($_GET["type"] == 4) $where = " format = 'PSP' "; else if ($_GET["type"] == 5) $where = " format = 'Nintendo DS' "; else if ($_GET["type"] == 6) $where = " format = 'Nintendo Wii' "; //elseif på övriga ryper ner till... else if ($_GET["type"] == 7) $where =" format = 'Xbox 360' "; else { //Vad du vill ska hända då - //tex att resultatet blir som för "alla" eller ett felmeddelande eller...? } //OM det är frågan ovan som gäller har du inga andra WHERE villkor, så... if (strlen($where) > 0) $where = "WHERE '$where'"; ?> <?php $query = "SELECT * FROM game $where ORDER BY id DESC $limit"; $result = mysql_query($query); if(mysql_num_rows($result) == 0) { //No data in database echo "There was no news recorded in the database!"; } else { // Lopp through the data and output the news // Läs om funktionen här: http://se2.php.net/mysql_fetch_assoc echo "<br />"; echo "<center class='numbers'>"; for($i = 1; $i <= $maxPages; $i++) { if($i == $page) { echo "$i "; } else { echo "<a href=\"recensionsindex.php?page=$i\">$i</a> "; } } echo "</center>"; echo "<table width='480' cellpadding='0' cellspacing='0'>"; // start the tr counter value $trCounter =1; while($row = mysql_fetch_assoc($result)) { if($trCounter==1) { echo"<tr height='28' bgcolor='#333333'>"; echo "<td><span class=minklass><a href=\"recension.php?id=".$row['id']."\">".$row['game']."</a>"."</span>"."</td>"; echo "<td width='160'>"."<center>".$row['format']."</center>"."</td>"; echo "<td width='100'>"."<center>".$row['date']."</center>"."</td>"; echo"</tr>"; } if($trCounter==2) { echo"<tr height='28' bgcolor='#151515'>"; echo "<td><span class=minklass><a href=\"recension.php?id=".$row['id']."\">".$row['game']."</a>"."</span>"."</td>"; echo "<td width='160'>"."<center>".$row['format']."</center>"."</td>"; echo "<td width='100'>"."<center>".$row['date']."</center>"."</td>"; echo"</tr>"; // set to Zero and add one after the last loop $trCounter=0; } // reset counter value for the next loop $trCounter +=1; } echo "</table>"; echo "<br />"; echo "<center class='numbers'>"; for($i = 1; $i <= $maxPages; $i++) { if($i == $page) { echo "$i "; } else { echo "<a href=\"recensionsindex.php?page=$i\">$i</a> "; } } } echo "</center>"; ?> Here is the menu code: <?php $me = $_SERVER['PHP_SELF'];?> <ul id='menu'> <li><a href="<?php echo $me; ?>">Alla</a></li> <li><a href="<?php echo $me."?type=1"; ?>">PC</a></li> <li><a href="<?php echo $me."?type=2"; ?>">PS 2</a></li> <li><a href="<?php echo $me."?type=3"; ?>">PS 3</a></li> <li><a href="<?php echo $me."?type=4"; ?>">PSP</a></li> <li><a href="<?php echo $me."?type=5"; ?>">Nintendo DS</a></li> <li><a href="<?php echo $me."?type=6"; ?>">Nintendo Wii</a></li> <li><a href="<?php echo $me."?type=7"; ?>">Xbox 360</a></li> </ul> If somebody please could help me. Link to comment https://forums.phpfreaks.com/topic/78104-problem-with-varibel-and-where-code/ Share on other sites More sharing options...
trq Posted November 20, 2007 Share Posted November 20, 2007 In the very first query you have a variable called $where, it is not defined anywhere prior to use. Link to comment https://forums.phpfreaks.com/topic/78104-problem-with-varibel-and-where-code/#findComment-395282 Share on other sites More sharing options...
Beat_88 Posted November 20, 2007 Author Share Posted November 20, 2007 Oh I saw that now that you mentioned it. I took it away but it is still the same problem. I get the same wrong messages Link to comment https://forums.phpfreaks.com/topic/78104-problem-with-varibel-and-where-code/#findComment-395284 Share on other sites More sharing options...
Beat_88 Posted November 20, 2007 Author Share Posted November 20, 2007 If anyone please could help me. This is the last thing for my site when I am done with this part I can finaly release the site. Please Link to comment https://forums.phpfreaks.com/topic/78104-problem-with-varibel-and-where-code/#findComment-395332 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.