Jump to content

[SOLVED] Data not displaying.


Ameslee

Recommended Posts

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]
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

[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?
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

[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!
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

[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!
Link to comment
Share on other sites

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=3

Change the 3 to a value that exists as an eventid in your database. Is this the effect you want?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.