DaveLinger Posted July 15, 2006 Share Posted July 15, 2006 The code:[code]<?phpinclude('includes/config.php');include('includes/header.php');$sid = $_GET['sid'];if (!$link = mysql_connect($sqlserver, $sqlusername, $sqlpassword)) { echo 'Could not connect to mysql'; exit;}if (!mysql_select_db($sqldatabase, $link)) { echo 'Could not select database'; exit;}$query="SELECT *, DATE_FORMAT(time, '%W, %M %D') AS my_date FROM nuke_stories WHERE sid = $sid";$result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());echo $query;while ($row = mysql_fetch_assoc()){$sid = $row['sid'];$title = $row['title'];$hometext = $row['hometext'];$counter = $row['counter'];$my_date = $row['my_date'];echo "<p>● <b>$title</b> - Posted by $aid on $my_date<br>$hometext</p>";}include('includes/footer.php');?>[/code]echos only the header and footer. I echoed the query and it shows as "SELECT *, DATE_FORMAT(time, '%W, %M %D') AS my_date FROM nuke_stories WHERE sid = 1238", sounds right to me, so why isnt it displaying anything or giving an error? I double checked the db to make sure the table columns match exactly... Quote Link to comment https://forums.phpfreaks.com/topic/14647-another-sql-problem-fun-fun/ Share on other sites More sharing options...
pixy Posted July 15, 2006 Share Posted July 15, 2006 You need to do this...if ($result) { // do stuff}else { echo mysql_error();} Quote Link to comment https://forums.phpfreaks.com/topic/14647-another-sql-problem-fun-fun/#findComment-58332 Share on other sites More sharing options...
DaveLinger Posted July 15, 2006 Author Share Posted July 15, 2006 whats wrong with$result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());? Quote Link to comment https://forums.phpfreaks.com/topic/14647-another-sql-problem-fun-fun/#findComment-58333 Share on other sites More sharing options...
BillyBoB Posted July 15, 2006 Share Posted July 15, 2006 maybe the . instead of ,or im saying it wrong put , instead . if not srry i wasted our time lol Quote Link to comment https://forums.phpfreaks.com/topic/14647-another-sql-problem-fun-fun/#findComment-58335 Share on other sites More sharing options...
pixy Posted July 15, 2006 Share Posted July 15, 2006 Well that way it returns TRUE if it worked and you know it's sucessfully, if it doesn't work then you handle the error.Honestly, I have put "or die(mysql_error());" but I always check if the query was sucessful first. What's better is to do something like...if (mysql_num_rows($result) != 0) { // do while loop}else { echo 'There is nothing in the database that matches criteria.';}Oh, and since you're using double quotes you don't have to due the concatenation . to put the mysql_error() with the message. I make a habbit of coding with single quotes since it's faster for the script to process when it doesn't have to parse for variables and code... Quote Link to comment https://forums.phpfreaks.com/topic/14647-another-sql-problem-fun-fun/#findComment-58337 Share on other sites More sharing options...
redarrow Posted July 15, 2006 Share Posted July 15, 2006 while ($row = mysql_fetch_assoc($result)) <<<<<<<<<<<<<<<<<<<<<<<<< Quote Link to comment https://forums.phpfreaks.com/topic/14647-another-sql-problem-fun-fun/#findComment-58338 Share on other sites More sharing options...
DaveLinger Posted July 15, 2006 Author Share Posted July 15, 2006 redarrow, are you married?...thanks... Quote Link to comment https://forums.phpfreaks.com/topic/14647-another-sql-problem-fun-fun/#findComment-58347 Share on other sites More sharing options...
pixy Posted July 15, 2006 Share Posted July 15, 2006 [quote author=redarrow link=topic=100639.msg397509#msg397509 date=1152934652]while ($row = mysql_fetch_assoc($result)) <<<<<<<<<<<<<<<<<<<<<<<<<[/quote] Whoa, I totally missed that. XD Also, if you are naming the fields specifically you can use mysql_fetch_array($result, MYSQL_NUM); and refer to $row[0] for the first row returned, $row[1], etc--I'm pretty sure it's supposed to be faster. Quote Link to comment https://forums.phpfreaks.com/topic/14647-another-sql-problem-fun-fun/#findComment-58353 Share on other sites More sharing options...
redarrow Posted July 15, 2006 Share Posted July 15, 2006 Anytime Mate.your welcome.pixy..................................lol Quote Link to comment https://forums.phpfreaks.com/topic/14647-another-sql-problem-fun-fun/#findComment-58360 Share on other sites More sharing options...
akitchin Posted July 15, 2006 Share Posted July 15, 2006 the difference in speed would be unnoticeable for such a short query and loop. Quote Link to comment https://forums.phpfreaks.com/topic/14647-another-sql-problem-fun-fun/#findComment-58380 Share on other sites More sharing options...
pixy Posted July 15, 2006 Share Posted July 15, 2006 Well, one day, DaveLinger will have many entries and it will make a 0.000003 second difference. So THERE. Quote Link to comment https://forums.phpfreaks.com/topic/14647-another-sql-problem-fun-fun/#findComment-58562 Share on other sites More sharing options...
DaveLinger Posted July 15, 2006 Author Share Posted July 15, 2006 heck, it would probably make a 0.000003 second difference NOW! Quote Link to comment https://forums.phpfreaks.com/topic/14647-another-sql-problem-fun-fun/#findComment-58713 Share on other sites More sharing options...
pixy Posted July 15, 2006 Share Posted July 15, 2006 The point is, my way is beterrrrrrrrrr. :D Quote Link to comment https://forums.phpfreaks.com/topic/14647-another-sql-problem-fun-fun/#findComment-58720 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.