justlukeyou Posted February 17, 2011 Share Posted February 17, 2011 I set up the following code to successfully individual items based on the id number. ?id=1 etc. However, I thought it would be simple to change to show another row so I changed all the terms to 'description'. However, if I enter ?description=abcde it shows nothing. But if I type in ?description=description is bizarrely shows everything. The only thing I can only put it down to is numbers. Does $_GET react differently react differently to numbers or does it require commas surrounding the string? <?php if( isset($_GET['description'])) $_GET['description']; $query = "SELECT * FROM productfeed WHERE description = $description LIMIT 0, 10"; $fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>'); while($row = mysql_fetch_array($fetchdata)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; echo "<div class='productdisplayshell'> <div class='productdisplayoutline'> <div class='productborder'><center> <a href='$link' target='_blank'><img src='$image'/></a> </center> </div></div> <div class='productdescriptionoutline'> <div class='productdescriptionbox'> <a href='$link' target='_blank' >$description</a> </div> <div class='productfulldescriptionbox'>$fulldescription</div> </div> <div class='productpriceoutline'> <div class='productpricebox'> <center>£ $price</center> </div> <div class='productbuybutton'> <center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center> </div> </div> </div>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/ Share on other sites More sharing options...
Pikachu2000 Posted February 17, 2011 Share Posted February 17, 2011 You never define $description anywhere before using it in your query. Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1175830 Share on other sites More sharing options...
justlukeyou Posted February 17, 2011 Author Share Posted February 17, 2011 Thanks, I have tried the following but it just brings up an error regardless of what I search. I have not tried to define it anywhere. <?php $query = "SELECT * FROM productfeed WHERE $description = LIMIT 0, 10"; $fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>'); while($row = mysql_fetch_array($fetchdata)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; echo "<div class='productdisplayshell'> <div class='productdisplayoutline'> <div class='productborder'><center> <a href='$link' target='_blank'><img src='$image'/></a> </center> </div></div> <div class='productdescriptionoutline'> <div class='productdescriptionbox'> <a href='$link' target='_blank' >$description</a> </div> <div class='productfulldescriptionbox'>$fulldescription</div> </div> <div class='productpriceoutline'> <div class='productpricebox'> <center>£ $price</center> </div> <div class='productbuybutton'> <center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center> </div> </div> </div>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1175837 Share on other sites More sharing options...
Pikachu2000 Posted February 17, 2011 Share Posted February 17, 2011 And the error is . . . ? Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1175865 Share on other sites More sharing options...
justlukeyou Posted February 19, 2011 Author Share Posted February 19, 2011 Hi, It just comes up with the following 'error' its as if it doesn't know what string to query so doesn't bring back any results. query: SELECT * FROM productfeed WHERE description = LIMIT 0, 10 Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1176872 Share on other sites More sharing options...
Pikachu2000 Posted February 19, 2011 Share Posted February 19, 2011 $description is undefined. You should be developing with error_reporting = -1 and display_errors = On in your php.ini file. That problem would have been reported. Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1176873 Share on other sites More sharing options...
justlukeyou Posted February 19, 2011 Author Share Posted February 19, 2011 Thanks, I tried that but it still keeps up with the same message. When I was using the idea number it was working fine but when I try to use the same principal on other strings it doesn't work. Previously I had this $query = "SELECT * FROM productfeed WHERE id = $id"; --------> id1 $query = "SELECT * FROM productfeed WHERE description = $description --------> I dont want the first description to be in place but everything I try just comes back with the message query: SELECT * FROM productfeed WHERE description = description LIMIT 0, 10 Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1176879 Share on other sites More sharing options...
Pikachu2000 Posted February 19, 2011 Share Posted February 19, 2011 Where is $description supposed to get its value if you never assign it one? Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1176888 Share on other sites More sharing options...
justlukeyou Posted February 19, 2011 Author Share Posted February 19, 2011 Thanks, I now have the following code. When I use this as my link: phpdescriptionresults.php?description=Description it displays everything in my database. But if I try: phpdescriptionresults.php?description=Descriptionproduct It comes up with the following error: query: SELECT * FROM productfeed WHERE description = Descriptionproduct This has an error: Unknown column 'Descriptionproduct' in 'where clause' I am setting the only output to description? <?php if (isset($_GET['description'])) $query = "SELECT * FROM productfeed WHERE description = $description"; $fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>'); while($row = mysql_fetch_array($fetchdata)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1176891 Share on other sites More sharing options...
litebearer Posted February 19, 2011 Share Posted February 19, 2011 This is what Pika means... change this: <?php if( isset($_GET['description'])) $_GET['description']; $query = "SELECT * FROM productfeed WHERE description = $description LIMIT 0, 10"; $fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>'); while($row = mysql_fetch_array($fetchdata)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; to this: <?php if( isset($_GET['description'])) $description = $_GET['description']; $query = "SELECT * FROM productfeed WHERE description = $description LIMIT 0, 10"; $fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>'); while($row = mysql_fetch_array($fetchdata)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; /* redundent line removed here */ $fulldescription = $row['fulldescription']; $price = $row['price']; Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1176906 Share on other sites More sharing options...
justlukeyou Posted February 19, 2011 Author Share Posted February 19, 2011 Hi, Thanks I have tried this but it does something a bit unusual. I have the description in a line text. For example "Red Widget" and "Blue Widget" but instead of showing "Red Widget" it has changed all the descriptions to "Description". Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1176909 Share on other sites More sharing options...
litebearer Posted February 19, 2011 Share Posted February 19, 2011 post your most recent revision in its entirety Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1176924 Share on other sites More sharing options...
sasa Posted February 20, 2011 Share Posted February 20, 2011 change your query to $query = "SELECT * FROM productfeed WHERE description = '$description' LIMIT 0, 10"; string value in SQL must be qvouted Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1177083 Share on other sites More sharing options...
justlukeyou Posted February 20, 2011 Author Share Posted February 20, 2011 Hi, If I use the following code it displays everything in the database and changes the description of each $description to "description". if( isset($_GET['description'])) $description = $_GET['description']; $query = "SELECT * FROM productfeed WHERE description = $description LIMIT 0, 10"; $fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>'); while($row = mysql_fetch_array($fetchdata)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; /* redundent line removed here */ $fulldescription = $row['fulldescription']; $price = $row['price']; However, if just add the following single commas likes this I get a blank screen so I'm quite puzzled as to whats doing. Ive tried around 20 variations but this seems to be the closest I can get it. $query = "SELECT * FROM productfeed WHERE description = '$description' LIMIT 0, 10"; Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1177227 Share on other sites More sharing options...
justlukeyou Posted February 20, 2011 Author Share Posted February 20, 2011 Actually, if I remove /* redundent line removed here */ and enter back in the following it no longer replaces each description with "description" but now shows the correct description. $description = $row['description']; However, it now shows every product in database when I use "phpdescriptionresults2.php?description=description" in the search bar but if use "phpdescriptionresults2.php?description=redwidget" it comes with the following error: query: SELECT * FROM productfeed WHERE productname = redwidget LIMIT 0, 10 This has an error: Unknown column 'productname' in 'where clause' So I am back to where I was earlier. At least I think I am! Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1177231 Share on other sites More sharing options...
Pikachu2000 Posted February 20, 2011 Share Posted February 20, 2011 Does the productfeed table actually have a field named `productname`? Also post the url string, from the filename to the end, that appears in the address bar when the error occurs. Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1177235 Share on other sites More sharing options...
justlukeyou Posted February 20, 2011 Author Share Posted February 20, 2011 Hi, Excluding the full domain name this (/test/phpdescriptionresults2.php?description=description) shows every items. This (/test/phpdescriptionresults2.php?description=redwidget) shows the following error: query: SELECT * FROM productfeed WHERE description = redwidget LIMIT 0, 10 This has an error: Unknown column 'redwidget' in 'where clause'. I just cant see why only the "description" works instead of the actual product name. Is it because I am using "description" twice. In the echo and as a query? This is the full code I have currently: <?php if( isset($_GET['description'])) $description = $_GET['description']; $query = "SELECT * FROM productfeed WHERE description = $description LIMIT 0, 10"; $fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>'); while($row = mysql_fetch_array($fetchdata)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; echo "<div class='productdisplayshell'> <div class='productdisplayoutline'> <div class='productborder'><center> <a href='$link' target='_blank'><img src='$image'/></a> </center> </div></div> <div class='productdescriptionoutline'> <div class='productdescriptionbox'> <a href='$link' target='_blank' >$description</a> </div> <div class='productfulldescriptionbox'>$fulldescription</div> </div> <div class='productpriceoutline'> <div class='productpricebox'> <center>&#163; $price</center> </div> <div class='productbuybutton'> <center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center> </div> </div> </div>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1177237 Share on other sites More sharing options...
Pikachu2000 Posted February 20, 2011 Share Posted February 20, 2011 Let's start with this: description=description is no different than writing 1=1. It will always be true, and therefore will match every record in the database. In the query string, $description needs to be in quotes: WHERE description = '$description'. But, since your form is somehow sending the string literal 'description', it probably won't match any records at all, unless the value in the record's description field is actually 'description'. Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1177245 Share on other sites More sharing options...
justlukeyou Posted February 20, 2011 Author Share Posted February 20, 2011 Hi, The title of field is 'description' as this is the one I am echoing so I know it works. I did try the following but it didn't do anything. Is there anything else I can do to improve the situation? if( isset($_GET['productname'])) $description = $_GET['productname']; $query = "SELECT * FROM productfeed WHERE productname = $description LIMIT 0, 10";$fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>'); Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1177250 Share on other sites More sharing options...
Pikachu2000 Posted February 20, 2011 Share Posted February 20, 2011 You MUST quote '$description' in the query string. An explanation of exactly what you're trying to achieve, and all of the relevant code, including the form is about the only way anyone is going to be able to help any further. Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1177251 Share on other sites More sharing options...
justlukeyou Posted February 20, 2011 Author Share Posted February 20, 2011 Hi, Many thanks, I am trying to aichieve this: "phpdescriptionresults2.php?description=red-widget" --- For this to display every 'red widget' in my database. Following is all the code I have: <?php if( isset($_GET['description'])) $description = $_GET['description']; $query = "SELECT * FROM productfeed WHERE description = $description LIMIT 0, 10"; $fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>'); while($row = mysql_fetch_array($fetchdata)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; echo "<div class='productdisplayshell'> <div class='productdisplayoutline'> <div class='productborder'><center> <a href='$link' target='_blank'><img src='$image'/></a> </center> </div></div> <div class='productdescriptionoutline'> <div class='productdescriptionbox'> <a href='$link' target='_blank' >$description</a> </div> <div class='productfulldescriptionbox'>$fulldescription</div> </div> <div class='productpriceoutline'> <div class='productpricebox'> <center>&#163; $price</center> </div> <div class='productbuybutton'> <center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center> </div> </div> </div>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1177257 Share on other sites More sharing options...
kenrbnsn Posted February 20, 2011 Share Posted February 20, 2011 As others have said, strings MUST be quoted in the query. Change: <?php $query = "SELECT * FROM productfeed WHERE description = $description LIMIT 0, 10"; ?> to <?php $query = "SELECT * FROM productfeed WHERE description = '$description' LIMIT 0, 10"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1177258 Share on other sites More sharing options...
justlukeyou Posted February 20, 2011 Author Share Posted February 20, 2011 Thanks, but when I try that I just get a blank screen. Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1177260 Share on other sites More sharing options...
kenrbnsn Posted February 20, 2011 Share Posted February 20, 2011 Then there's something else wrong. Ken Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1177263 Share on other sites More sharing options...
justlukeyou Posted February 20, 2011 Author Share Posted February 20, 2011 If I put the following -----here curlys in does something very wierd. It only shows the description I am searching and cuts out everything else such as the image. Is it possible to get a code which overrights what is in the string because that is what I appear to be doing. <?php if( isset($_GET['description'])) $description = $_GET['description']; $query = "SELECT * FROM productfeed WHERE description = '$description' LIMIT 0, 10"; $fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>'); while($row = mysql_fetch_array($fetchdata)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; } -----here { -----here echo "<div class='productdisplayshell'> <div class='productdisplayoutline'> <div class='productborder'><center> <a href='$link' target='_blank'><img src='$image'/></a> </center> </div></div> <div class='productdescriptionoutline'> <div class='productdescriptionbox'> <a href='$link' target='_blank' >$description</a> </div> <div class='productfulldescriptionbox'>$fulldescription</div> </div> <div class='productpriceoutline'> <div class='productpricebox'> <center>&#163; $price</center> </div> <div class='productbuybutton'> <center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center> </div> </div> </div>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/#findComment-1177267 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.