Jump to content

Recommended Posts

Not new to programming, but an infant in PHP. I'm using the following code to get a value from a mySql table. The table has seven columns, one row, field Ronum is mediumint with a value of 1 in it and is the primary key. The following code runs fine, but when I get to the echo row/ronum at the bottom, $row contains only "ARRAY", and $ronum is blank. Don't get it.:

<?php
$user="root";
$host="localhost";
$password="";
$database = "Vshop";
  $connection = mysql_connect($host,$user,$password)
    or die ("couldn't connect to server");
  $db = mysql_select_db($database,$connection)
    or die ("Couldn't select database");
{
  $query = "Select Ronum From ro";
}
$result = mysql_query($query)
    or die ("Couldn't execute query.");
$row = mysql_fetch_array($result,MYSQL_NUM);
extract ($row);
echo "$row";
echo "$ronum";
?>

  Any help is greatly appreciated.
$row is an array of your data, with the field names as array elements.  extracting $row will create variables having the same name as your field names. do this loop to see what is actually being retrieved, and then you will see what variables are being extracted.

foreach ($row as $key => $val) {
  echo "key: $key  value: $val <br>";
}

the "key" is the variable names that extract should build.
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.