I am still trying to get a grasp on the php/mysql interaction. Why does something like this not work and without all the error catching, can one do something like this?

$result = mysql_query("SELECT * FROM stadium WHERE gametime = `$_z`;");
      $row = mysql_fetch_row($result);
      $bababa[name] = $row[0];
      $bababa[town] = $row[1];
      $bababa[playingA] = $row[2];
      $bababa[playingB] = $row[3];
      $bababa[3] = $row[4];      
      return $bababa;

What exactly is stored in $row in this case?

It depends on what and howmuch columns you have in your table. For example, ExampleTable exists out of 5 columns:

user CHAR(255), <- PRIMARY KEY
firstname CHAR(255),
lastname CHAR(255),
telephone INT(20) and
zip INT(7)

Then if you execute the following query:

<?php
//
// Creating query and executing it
//
$query = "SELECT * FROM ExampleTable";
$result = mysql_fetch_array($query);
//
// As long as $row has a result, it executes what is inside the {}
//
while ($row = mysql_fetch_array($result)) {
//
// Putting $row[''] variables in separate variables
//
$user = $row['user'];
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$telephone = $row['telephone'];
$zip = $row['zip'];
//
// Showing the result
//
echo "
User: ".$user."<br />
Firstname: ".$firstname."<br />
Lastname: ".$lastname."<br />
Telephone: ".$telephone."<br />
Zip: ".$zip."<br /><br />";
}
?>

Okay, I am still going around in circles and not getting it to work. Let me put my actual code rather than trying to make up examples. This is for a blog, which I actually had working fine (well, this part of it), but I am building the whole thing into a class now, to make it easier to work with.

This is what I have it at now. The $_ptimeValref that gets passed to the function is right (I got it to echo it.) I tried "SELECT * FROM post WHERE ptime ='$_ptimeValref' and changing the * to post, title, ptime. I realize that I must just not be getting it. Each time I have done this I have gone through the same process, finally getting something that works, but not really sure why it does, and why so many other things I tried didn't.

function getPostValues($_ptimeValref){
          /* This function gets the value of ptime
          and returns the full set of values for a post: 
          post url, title and ptime as a time value */
          
      include 'DB_connection.php';
      $query = "SELECT * FROM post";
      $result = mysql_fetch_assoc($query);
      while ($row = mysql_fetch_array($result)){
          if ($row['ptime'] = $_ptimeValref){
              $post['url'] = $row['post'];
              $post['title'] = $row['title'];
              $post['ptime'] = $row['ptime'];
              }
          }
      return $post;     
  }

Okay, I am still going around in circles and not getting it to work. Let me put my actual code rather than trying to make up examples. This is for a blog, which I actually had working fine (well, this part of it), but I am building the whole thing into a class now, to make it easier to work with.

This is what I have it at now. The $_ptimeValref that gets passed to the function is right (I got it to echo it.) I tried "SELECT * FROM post WHERE ptime ='$_ptimeValref' and changing the * to post, title, ptime. I realize that I must just not be getting it. Each time I have done this I have gone through the same process, finally getting something that works, but not really sure why it does, and why so many other things I tried didn't.

function getPostValues($_ptimeValref){
          /* This function gets the value of ptime
          and returns the full set of values for a post: 
          post url, title and ptime as a time value */
          
      include 'DB_connection.php';
      $query = "SELECT * FROM post";
      $result = mysql_fetch_assoc($query);
      while ($row = mysql_fetch_array($result)){
          if ($row['ptime'] = $_ptimeValref){
              $post['url'] = $row['post'];
              $post['title'] = $row['title'];
              $post['ptime'] = $row['ptime'];
              }
          }
      return $post;     
  }

i think u r missing the actual queryin part. you'll obviously need mysql_query(....) ainni?
i think ur $result shud be equated to mysql_query($query)

It depends on what and howmuch columns you have in your table. For example, ExampleTable exists out of 5 columns:

user CHAR(255), <- PRIMARY KEY
firstname CHAR(255),
lastname CHAR(255),
telephone INT(20) and
zip INT(7)

Then if you execute the following query:

<?php
//
// Creating query and executing it
//
$query = "SELECT * FROM ExampleTable";
$result = mysql_fetch_array($query);
//
// As long as $row has a result, it executes what is inside the {}
//
while ($row = mysql_fetch_array($result)) {
//
// Putting $row[''] variables in separate variables
//
$user = $row['user'];
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$telephone = $row['telephone'];
$zip = $row['zip'];
//
// Showing the result
//
echo "
User: ".$user."<br />
Firstname: ".$firstname."<br />
Lastname: ".$lastname."<br />
Telephone: ".$telephone."<br />
Zip: ".$zip."<br /><br />";
}
?>

Sorry saw horrible mistake in my post:

$result = mysql_fetch_array($query);

needs to be

$result = mysql_query($query);

~G

Wonderful. You have no idea how much this little bit of help is a means!

You've to check your query first wheather it gives answer or not.

$result = mysql_query("SELECT * FROM stadium WHERE gametime = `$_z`") or die(mysql_error());
      $row = mysql_fetch_row($result);
      $bababa[name] = $row[0];
      $bababa[town] = $row[1];
      $bababa[playingA] = $row[2];
      $bababa[playingB] = $row[3];
      $bababa[3] = $row[4];      
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.