jaxdevil Posted October 8, 2008 Share Posted October 8, 2008 It is not returning any results, when I run that exact $sql in phpmyadmin it returns results. Anyone see what I am missing? <? require($_SERVER['DOCUMENT_ROOT'].'/includes/configs/sql_connect.php'); $sql = 'SELECT * FROM products_description WHERE model_number=\'JT20-A8450\''; $query = mysql_query($sql) or die ("MySQL Error: " . mysql_error()); while($row = mysql_fetch_array($query)){ $descriptions = $row['$id']; echo $descriptions; echo $row[$description]; } ?> Link to comment https://forums.phpfreaks.com/topic/127589-solved-something-wrong-in-this-queryhas-to-be-simple-i-just-cant-get-it/ Share on other sites More sharing options...
budimir Posted October 8, 2008 Share Posted October 8, 2008 Try this: <? require($_SERVER['DOCUMENT_ROOT'].'/includes/configs/sql_connect.php'); $sql = "SELECT * FROM products_description WHERE model_number=\'JT20-A8450\'"; $query = mysql_query($sql) or die ("MySQL Error: " . mysql_error()); while($row = mysql_fetch_array($query)){ $descriptions = $row['$id']; echo $descriptions; echo $row[$description]; } ?> Link to comment https://forums.phpfreaks.com/topic/127589-solved-something-wrong-in-this-queryhas-to-be-simple-i-just-cant-get-it/#findComment-660154 Share on other sites More sharing options...
jaxdevil Posted October 8, 2008 Author Share Posted October 8, 2008 Nope, still returning nothing. Anything else? Link to comment https://forums.phpfreaks.com/topic/127589-solved-something-wrong-in-this-queryhas-to-be-simple-i-just-cant-get-it/#findComment-660157 Share on other sites More sharing options...
PFMaBiSmAd Posted October 8, 2008 Share Posted October 8, 2008 What exactly is the output to the browser. And what does the "view source" of the page in the browser show? Link to comment https://forums.phpfreaks.com/topic/127589-solved-something-wrong-in-this-queryhas-to-be-simple-i-just-cant-get-it/#findComment-660158 Share on other sites More sharing options...
darkfreaks Posted October 8, 2008 Share Posted October 8, 2008 using server document root is bad practice do something like <?php define('WEB_ROOT', 'path to root folder here'); require (WEB_ROOT .'/includes/configs/sql_connect.php'); ?> Link to comment https://forums.phpfreaks.com/topic/127589-solved-something-wrong-in-this-queryhas-to-be-simple-i-just-cant-get-it/#findComment-660160 Share on other sites More sharing options...
monkeytooth Posted October 8, 2008 Share Posted October 8, 2008 WHERE model_number=\'JT20-A8450\'" why do you have the slashes? I think that may be the issue try removing those slashes, as they arent needed cause your not trying to break any quotes with them.. so above to.. WHERE model_number='JT20-A8450'" does that help? Link to comment https://forums.phpfreaks.com/topic/127589-solved-something-wrong-in-this-queryhas-to-be-simple-i-just-cant-get-it/#findComment-660161 Share on other sites More sharing options...
monkeytooth Posted October 8, 2008 Share Posted October 8, 2008 better yet.. replace.. $sql = mysql_query("SELECT * FROM products_description WHERE model_number='JT20-A8450'"); $query = mysql_num_rows($sql); // returns number of rows should you need that $query_a = mysql_fetch_array($sql); // returns the array of info from the row while($row = mysql_fetch_array($query)){ $descriptions = $row['$id']; echo $descriptions; echo $row[$description]; } Link to comment https://forums.phpfreaks.com/topic/127589-solved-something-wrong-in-this-queryhas-to-be-simple-i-just-cant-get-it/#findComment-660163 Share on other sites More sharing options...
jaxdevil Posted October 8, 2008 Author Share Posted October 8, 2008 Nope, I put the document root so I can move the script between websites. I tried without the slashes and with the actual connection string on the page, i put sample text below the script of 'test' to make sure the script wasn't breaking. So the only thing output to the browser is the text 'test'. Here is the code, with the slashes removed, and the connection string with the username password changed of course. It is the right connection string and the fields are in the database. I even tried like below with a LIKE statement and just a wildcard, still nothing. <? mysql_connect('localhost','xxx_xxx','xxx'); mysql_select_db('xxx_xxx'); $sql = "SELECT * FROM products_description WHERE model_number LIKE '%'"; $query = mysql_query($sql) or die ("MySQL Error: " . mysql_error()); while($row = mysql_fetch_array($query)){ $descriptions = $row['$id']; echo $descriptions; echo $row[$description]; } ?> Link to comment https://forums.phpfreaks.com/topic/127589-solved-something-wrong-in-this-queryhas-to-be-simple-i-just-cant-get-it/#findComment-660164 Share on other sites More sharing options...
monkeytooth Posted October 8, 2008 Share Posted October 8, 2008 edit:... while($row = mysql_fetch_array($query_a)){ $descriptions = $row['$id']; echo $descriptions; echo $row[$description]; } Link to comment https://forums.phpfreaks.com/topic/127589-solved-something-wrong-in-this-queryhas-to-be-simple-i-just-cant-get-it/#findComment-660165 Share on other sites More sharing options...
jaxdevil Posted October 8, 2008 Author Share Posted October 8, 2008 I tried with the below, nothing returned other than the text 'test': $sql = "SELECT * FROM products_description WHERE model_number LIKE '%'"; $query = mysql_num_rows($sql); // returns number of rows should you need that $query_a = mysql_fetch_array($sql); // returns the array of info from the row while($row = mysql_fetch_array($query_a)){ $descriptions = $row['$id']; echo $descriptions; echo $row[$description]; } Link to comment https://forums.phpfreaks.com/topic/127589-solved-something-wrong-in-this-queryhas-to-be-simple-i-just-cant-get-it/#findComment-660167 Share on other sites More sharing options...
monkeytooth Posted October 8, 2008 Share Posted October 8, 2008 is "test".. the product description you have stored? Link to comment https://forums.phpfreaks.com/topic/127589-solved-something-wrong-in-this-queryhas-to-be-simple-i-just-cant-get-it/#findComment-660172 Share on other sites More sharing options...
jaxdevil Posted October 8, 2008 Author Share Posted October 8, 2008 No, I added 'test' as text after the code so I could make sure the script wasn't breaking. I figured it out though: <? require($_SERVER['DOCUMENT_ROOT'].'/includes/configs/sql_connect.php'); $result = mysql_query("SELECT * FROM products_description WHERE model_number='JT20-A8450'") or die(mysql_error()); $row = mysql_fetch_array($result); echo $row['id']; echo "<br>"; echo $row['description']; ?> Link to comment https://forums.phpfreaks.com/topic/127589-solved-something-wrong-in-this-queryhas-to-be-simple-i-just-cant-get-it/#findComment-660173 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.