Jump to content

Recommended Posts

Hi! from code below, you can see am trying to get a field value to my variables $point1... from record one to 19. But it not working. the part that is not working is  $point1= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=1");...

 

Help!

 

Which is the way out?

 

<?PHP
$con = mysql_connect("localhost","root","superman");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("digitaldevidemt", $con);

$result = mysql_query("SELECT*FROM tblkenya WHERE Par_Id=1");


while($row = mysql_fetch_array($result))
  {  
   $point1= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=1");
   $point2= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=2");
   $point3= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=3");
   $point4= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=4");
   $point5= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=5");
   $point6= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=6");
   $point7= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=7");
   $point8= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=8");
   $point9= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=9");
   $point10= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=10");
   $point11= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=11");
   $point12= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=12");
   $point13= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=13");
   $point14= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=14");
   $point15= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=15");
   $point16= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=16");
   $point17= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=17");
   $point18= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=18");
   $point19= mysql_query(("SELECT Par_Value FROM tblkenya WHERE ID=19");
     
  }
mysql_close($con);

?>

mysql_query does not return data from a query, it only returns a result resource identifier which will be used with functions such as mysql_fetch_array to retrieve the data from the database.

 

What are you trying to do? Retrieve the the first 19 rows from the tblkenya table? If you only want 19 results then use LIMIT to limit the amount of rows to be returned, eg:

$result = mysql_query("SELECT * FROM tblkenya ORDER BY ID ASC LIMIT 19");

while($row = mysql_fetch_assoc($result))
{ 
     echo '<pre>' . $row . '</pre>';
}

 

when usinga ny of the mysql_fetch_* functions in a while loop it'll return each row one by one every time PHP iterates through the while loop.

thanks i just woke up it morning here.

Now i want to be able to do as you have mentioned but now i want every record it fetches, be put in a variable e.g $point1,$point2..e.t.c rather than echo them on the page...

 

Thanks again!

 

Regards,

Joseph

$result = mysql_query("SELECT * FROM tblkenya ORDER BY ID ASC LIMIT 19");

while($row = mysql_fetch_assoc($result))
{ 
     $rows[] = $row;
}

foreach($rows as $key => $array){
  echo '<pre>';
  print_r($rows[$key]);
  echo '</pre>';
  //or
  echo $rows[$key]['somecolumname'];
}
//or
foreach($rows as $array){
  foreach($array as $key => $val){
    echo "$key = $val<br>";
  }
}
//u get the picture

thanks i just woke up it morning here.

Now i want to be able to do as you have mentioned but now i want every record it fetches, be put in a variable e.g $point1,$point2..e.t.c rather than echo them on the page...

 

Thanks again!

 

Regards,

Joseph

Can you explain what you're trying to do with the variables $point1, $point2 etc?

creat x and y points of a graph line.

 

e.g line (212,345) to (234,789) are two points of a line on a the graph, i get the database value then calculate to find the exact position value for the x and y. then echo it between the brackets above ...... something like that .... hope you understand.

 

Thanks for being concerned.

 

Regards,

Joseph

I got it figured out but there is another problem, i have hit a dead end to my adventure.

 

what i have iss an array of 10,20,30,40,50,60,70,80,90,100 y pane for value and

array 1995,1996,1997 ..to ..2008 the x pane for years.

 

my 10 array gieves an (x,y) co-ordinates of (92,441)

 

what is the formular for all other co-ordinates, that is my problem.

 

Help??

 

Thanks

 

 

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.