Ameslee Posted December 17, 2006 Share Posted December 17, 2006 Hello hope someone can help me. Can anyone tell me why the following code isnt displaying anything, just the headings.[code]<?php $hostname = localhost; $username = ; $password = ; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db("greenac_VORNExpo", $conn); $query = "SELECT * FROM `events` WHERE eventid='$id'"; $mysql_result=mysql_query($query,$conn); $row=mysql_fetch_row($mysql_result); $date=$row[2]; $day=substr($date,8,2); $month=substr($date,5,2); $year=substr($date,0,4); $date2=$day." - ".$month." - ".$year; echo("<table width=100%><tr><td width=10%><b>Event:</b><td width=35%>$row[1]"); echo("<tr><td width=10%><b>Date:</b><td width=35%>$date2"); echo("<tr><td width=10%><b>Cost:</b><td width=35%>$row[3]"); echo("<tr><td width=10%><b>Other Info:</b><td width=35%>$row[4]"); echo("<tr><td width=10%><b>Contact Person:</b><td width=35%>$row[5]"); echo("<tr><td width=10%><b>Contact Number:</b><td width=35%>$row[6]"); echo("<tr><td width=10%><b>Mobile:</b><td width=35%>$row[7]"); echo("<tr><td width=10%><b>Email:</b><td width=35%>$row[8]"); echo("</tr></table>"); ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/ Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 Does your query work? You never test it before trying to use it! This is a big no no.Also, a more descriptive title would be nice. Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143192 Share on other sites More sharing options...
Ameslee Posted December 17, 2006 Author Share Posted December 17, 2006 it was working and now it isnt, i dont have a clue why? Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143193 Share on other sites More sharing options...
simcoweb Posted December 17, 2006 Share Posted December 17, 2006 Where is this variable being set?WHERE eventid='$id'";I'm assuming from a $_GET statement but none is present. The query needs to know that 'id' before it can produce results. Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143194 Share on other sites More sharing options...
Ameslee Posted December 17, 2006 Author Share Posted December 17, 2006 but it was displaying before fine, i dont even remember changing anything. Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143198 Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 [quote]it was working and now it isnt, i dont have a clue why?[/quote]How do you know its working? You don't test it before using it. At the very least, use a die() statement to catch any error.[code=php:0]$mysql_result=mysql_query($query,$conn) or die(mysql_error());[/code]The basic syntax for running a select statement should be...[code=php:0]if ($result = mysql_query($sql)) { if (mysql_num_rows($result) > 0) { // now you can be sure you have data. }}[/code]Without this kind of basic error handling your application is sure to fall to pieces. Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143202 Share on other sites More sharing options...
Ameslee Posted December 17, 2006 Author Share Posted December 17, 2006 [quote author=thorpe link=topic=119033.msg486917#msg486917 date=1166399275][quote]it was working and now it isnt, i dont have a clue why?[/quote]How do you know its working? You don't test it before using it. At the very least, use a die() statement to catch any error.[code=php:0]$mysql_result=mysql_query($query,$conn) or die(mysql_error());[/code]The basic syntax for running a select statement should be...[code=php:0]if ($result = mysql_query($sql)) { if (mysql_num_rows($result) > 0) { // now you can be sure you have data. }}[/code]Without this kind of basic error handling your application is sure to fall to pieces.[/quote]this didnt work! When i say it was working, i mean data was coming out of the database and being displayed on the page, with no problems before, so i dont know why it isnt now. I already have a $mysql_result=mysql_query($query,$conn) or die(mysql_error()); statement. Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143210 Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 [quote]this didnt work![/quote]Did you just copy / patse my code? I was showing you the simple logic of making a select query, not giving you working code.Post your current code. And as has been asked.... where does $id come from? Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143214 Share on other sites More sharing options...
Ameslee Posted December 18, 2006 Author Share Posted December 18, 2006 [code]<?php $hostname = localhost; $username = ; $password = ; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db("greenac_VORNExpo", $conn); $query = "SELECT * FROM `events` WHERE eventid='$eventid'"; $mysql_result=mysql_query($query,$conn); $row=mysql_fetch_row($mysql_result); $date=$row[2]; $day=substr($date,8,2); $month=substr($date,5,2); $year=substr($date,0,4); $date2=$day." - ".$month." - ".$year; echo("<table width=100%><tr><td width=10%><b>Event:</b><td width=35%>$row[1]"); echo("<tr><td width=10%><b>Date:</b><td width=35%>$date2"); echo("<tr><td width=10%><b>Cost:</b><td width=35%>$row[3]"); echo("<tr><td width=10%><b>Other Info:</b><td width=35%>$row[4]"); echo("<tr><td width=10%><b>Contact Person:</b><td width=35%>$row[5]"); echo("<tr><td width=10%><b>Contact Number:</b><td width=35%>$row[6]"); echo("<tr><td width=10%><b>Mobile:</b><td width=35%>$row[7]"); echo("<tr><td width=10%><b>Email:</b><td width=35%>$row[8]"); echo("</tr></table>"); ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143217 Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 Look. If your not going to take the time to try the suggested methods I post, I'll just stop posting. Debug your code! Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143219 Share on other sites More sharing options...
Ameslee Posted December 18, 2006 Author Share Posted December 18, 2006 im sorry, but im new at this, and possibly dont quite understand, plz help! Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143221 Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 What does this produce?[code]<?php // connect to database. $query = "SELECT * FROM `events` WHERE eventid='$eventid'"; if ($mysql_result = mysql_query($query,$conn)) { if (mysql_num_rows($mysql_result) > 0) { $row = mysql_fetch_row($mysql_result); $date = $row[2]; $day = substr($date,8,2); $month = substr($date,5,2); $year = substr($date,0,4); $date2 = $day." - ".$month." - ".$year; echo "<table width=100%><tr><td width=10%><b>Event:</b><td width=35%>$row[1]"; echo "<tr><td width=10%><b>Date:</b><td width=35%>$date2"; echo "<tr><td width=10%><b>Cost:</b><td width=35%>$row[3]"; echo "<tr><td width=10%><b>Other Info:</b><td width=35%>$row[4]"; echo "<tr><td width=10%><b>Contact Person:</b><td width=35%>$row[5]"; echo "<tr><td width=10%><b>Contact Number:</b><td width=35%>$row[6]"; echo "<tr><td width=10%><b>Mobile:</b><td width=35%>$row[7]"; echo "<tr><td width=10%><b>Email:</b><td width=35%>$row[8]"; echo "</tr></table>"; } else { echo "No results found"; } } else { echo "Query failed: ". mysql_error() . ": $query"; }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143226 Share on other sites More sharing options...
Ameslee Posted December 18, 2006 Author Share Posted December 18, 2006 [quote author=thorpe link=topic=119033.msg486941#msg486941 date=1166400652]What does this produce?[code]<?php // connect to database. $query = "SELECT * FROM `events` WHERE eventid='$eventid'"; if ($mysql_result = mysql_query($query,$conn)) { if (mysql_num_rows($mysql_result) > 0) { $row = mysql_fetch_row($mysql_result); $date = $row[2]; $day = substr($date,8,2); $month = substr($date,5,2); $year = substr($date,0,4); $date2 = $day." - ".$month." - ".$year; echo "<table width=100%><tr><td width=10%><b>Event:</b><td width=35%>$row[1]"; echo "<tr><td width=10%><b>Date:</b><td width=35%>$date2"; echo "<tr><td width=10%><b>Cost:</b><td width=35%>$row[3]"; echo "<tr><td width=10%><b>Other Info:</b><td width=35%>$row[4]"; echo "<tr><td width=10%><b>Contact Person:</b><td width=35%>$row[5]"; echo "<tr><td width=10%><b>Contact Number:</b><td width=35%>$row[6]"; echo "<tr><td width=10%><b>Mobile:</b><td width=35%>$row[7]"; echo "<tr><td width=10%><b>Email:</b><td width=35%>$row[8]"; echo "</tr></table>"; } else { echo "No results found"; } } else { echo "Query failed: ". mysql_error() . ": $query"; }?>[/code][/quote]"No Results Found" how can that be though? The record is in the database! Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143229 Share on other sites More sharing options...
chiprivers Posted December 18, 2006 Share Posted December 18, 2006 try taking out the WHERE eventid='$eventid' part of the queryie.$query = "SELECT * FROM `events`"; Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143237 Share on other sites More sharing options...
Ameslee Posted December 18, 2006 Author Share Posted December 18, 2006 [quote author=chiprivers link=topic=119033.msg486952#msg486952 date=1166401435]try taking out the WHERE eventid='$eventid' part of the queryie.$query = "SELECT * FROM `events`";[/quote]BINGO! That did it, thanks! All working now! Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143240 Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 [quote]"No Results Found" how can that be though? The record is in the database![/quote]This is the third time this question has been asked. Now, where are you defining $eventid?Your not. This is just a guess but try channging your query to...[code=php:0]$query = "SELECT * FROM `events` WHERE eventid='{$_GET['eventid']}'";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143241 Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 [quote]BINGO! That did it, thanks! All working now![/quote]That will select ALL records. Then only display the last one. This is very inificient. Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143243 Share on other sites More sharing options...
chiprivers Posted December 18, 2006 Share Posted December 18, 2006 [quote author=thorpe link=topic=119033.msg486958#msg486958 date=1166401639][quote]BINGO! That did it, thanks! All working now![/quote]That will select ALL records. Then only display the last one. This is very inificient.[/quote]Just thought if we did this we could confirm the problem was with not declaring $eventid like you suggested from the start. If only people would listen to the answers from the start! Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143246 Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 Yeah I know what your doing chip, Im afraid this op is probably gone now thinking its working. They'll be back soon enough asking..."why is this allways displaying the last event added?"Sheesh. Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143247 Share on other sites More sharing options...
Ameslee Posted December 18, 2006 Author Share Posted December 18, 2006 ok ok your right, gees, im new at this alright, im not meant to know everything. ok, i added this statement - $query = "SELECT * FROM `events` WHERE eventid='{$_GET['eventid']}'"; now it shows no result found. eventid is a field in the database! Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143254 Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 Ok, but in your query you had the variable $eventid. Where do you define this variable? Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143257 Share on other sites More sharing options...
Ameslee Posted December 18, 2006 Author Share Posted December 18, 2006 ok i really dont know, im getting really confused. eventid = primary key Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143261 Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 You put a variable in your query... where is it coming from? What is it meant to hold? Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143262 Share on other sites More sharing options...
Ameslee Posted December 18, 2006 Author Share Posted December 18, 2006 its coming from the events table in the database, it is the primary key, it holds the id of each event Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143263 Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 Sorry, but you are completely confused. The variable itself is used in the query to get the infomation from the database, so no, it cannot being comming from the database itself (because you are yet to get any data).I really can't help you much more, I can't push this stuff into your brain.As an example, use the query I gave you...[code=php:0]$query = "SELECT * FROM `events` WHERE eventid='{$_GET['eventid']}'";[/code]And call the page via a browser with something like....http://yoursite/thispage.php?eventid=3Change the 3 to a value that exists as an eventid in your database. Is this the effect you want? Quote Link to comment https://forums.phpfreaks.com/topic/31032-solved-data-not-displaying/#findComment-143265 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.