jkkenzie Posted April 4, 2008 Share Posted April 4, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/99561-get-data-from-mysql-table-from-different-records-of-a-field/ Share on other sites More sharing options...
wildteen88 Posted April 4, 2008 Share Posted April 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/99561-get-data-from-mysql-table-from-different-records-of-a-field/#findComment-509369 Share on other sites More sharing options...
jkkenzie Posted April 5, 2008 Author Share Posted April 5, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/99561-get-data-from-mysql-table-from-different-records-of-a-field/#findComment-509777 Share on other sites More sharing options...
benjaminbeazy Posted April 5, 2008 Share Posted April 5, 2008 $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 Quote Link to comment https://forums.phpfreaks.com/topic/99561-get-data-from-mysql-table-from-different-records-of-a-field/#findComment-509780 Share on other sites More sharing options...
wildteen88 Posted April 5, 2008 Share Posted April 5, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/99561-get-data-from-mysql-table-from-different-records-of-a-field/#findComment-509902 Share on other sites More sharing options...
jkkenzie Posted April 5, 2008 Author Share Posted April 5, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/99561-get-data-from-mysql-table-from-different-records-of-a-field/#findComment-509918 Share on other sites More sharing options...
jkkenzie Posted April 5, 2008 Author Share Posted April 5, 2008 still this does not help me, i cant echo a value into my variables! Please help. thanks Quote Link to comment https://forums.phpfreaks.com/topic/99561-get-data-from-mysql-table-from-different-records-of-a-field/#findComment-509939 Share on other sites More sharing options...
jkkenzie Posted April 5, 2008 Author Share Posted April 5, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/99561-get-data-from-mysql-table-from-different-records-of-a-field/#findComment-510040 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.