Jump to content

retrieve data from the database


vj5

Recommended Posts

This question seems very vague. If you need information regarding general select and updates, that is probably too basic for this forum (at least, I'm not willing to put in the time necessary to answer that). You are better off googling for a tutorial (w3schools also has help with databases: http://w3schools.com/sql/default.asp )If you've already made an attempt and are having issues, then please post again with more specifics regarding your problem.

Link to comment
Share on other sites

This question seems very vague. If you need information regarding general select and updates, that is probably too basic for this forum (at least, I'm not willing to put in the time necessary to answer that). You are better off googling for a tutorial (w3schools also has help with databases: http://w3schools.com/sql/default.asp )If you've already made an attempt and are having issues, then please post again with more specifics regarding your problem.
Here is my code for the select statement:
 Select * from `tblconfirm` where cid = '"caseid"' Order by caseid Desc LIMIT 1;

Now I want to retreive the data for the caseid one after another. I am also using HTTPS vars to extract data through URL. Does anyone know how to retreive only the caseid based on caseid one at a time?

Link to comment
Share on other sites

I'm not 100% sure if this is what you're talking about, but:first of, I'm assuming you know PHPnow, you need to store the mysql_query() in a variable (calling it $x for now)now we use this code

while ($y = mysql_fetch_array($x)){	echo $y["caseid"]."<br />";}

(this will print all of the caseid's - you can do whatever you want with themNow - while ($y = mysql_fetch_array($x)) is doing two things.The first is assigning the first row of the variable $x (which is a set of rows from a database) into the variable $y as an array. Every time we call mysql_fetch_array it will give us a new row, untill it runs out of them (then I think it returns false).The second thing that whole while... line does is continue looping until there are no more rows in $x. You might have noticed that $y = mysql_fetch_array($x) is not a conditional. while() works because as assignment itself has a value. The value of ($x = 5) is 5. Therefore, if we set $y = ($x + 5), we would be setting both $x and $y to 5. Note that you don't need the parenthesis, so $y = $x = 5 would do the same thing since assignments are read from right to left. So, while($y = mysql_fetch_array($x)) is the same as while(mysql_fetch_array($x)), with the added benefit of assigning that value to $y. So while() will loop for as many times as there are rows, using $y to deal with the particular row at hand.

Link to comment
Share on other sites

I'm not 100% sure if this is what you're talking about, but:first of, I'm assuming you know PHPnow, you need to store the mysql_query() in a variable (calling it $x for now)now we use this code
while ($y = mysql_fetch_array($x)){	echo $y["caseid"]."<br />";}

(this will print all of the caseid's - you can do whatever you want with themNow - while ($y = mysql_fetch_array($x)) is doing two things.The first is assigning the first row of the variable $x (which is a set of rows from a database) into the variable $y as an array. Every time we call mysql_fetch_array it will give us a new row, untill it runs out of them (then I think it returns false).The second thing that whole while... line does is continue looping until there are no more rows in $x. You might have noticed that $y = mysql_fetch_array($x) is not a conditional. while() works because as assignment itself has a value. The value of ($x = 5) is 5. Therefore, if we set $y = ($x + 5), we would be setting both $x and $y to 5. Note that you don't need the parenthesis, so $y = $x = 5 would do the same thing since assignments are read from right to left. So, while($y = mysql_fetch_array($x)) is the same as while(mysql_fetch_array($x)), with the added benefit of assigning that value to $y. So while() will loop for as many times as there are rows, using $y to deal with the particular row at hand.

No. I am learning php on the job. how do I assign mysql_query variable. Should i have to declare somewhere along the codes. is this right?
$qry = mysql_query($x)while ($y = mysql_fetch_array($x)){	echo $y["caseid"]."<br />";}

Link to comment
Share on other sites

No. I am learning php on the job. how do I assign mysql_query variable. Should i have to declare somewhere along the codes. is this right?
$qry = mysql_query($x)while ($y = mysql_fetch_array($x)){	echo $y["caseid"]."<br />";}

Close, it's actually:
$x = mysql_query("SELECT * FROM.... (i.e. the SQL query)","the name of the connection to the database, this is optional assuming you have already connected to the database");while ($y = mysql_fetch_array($x)){	echo $y["caseid"]."<br />";}

before you can access the database, you need to connect to it usingmysql_connect()you should run a command at the beginning of the document:

$con = mysql_connect(servername,username,password);

then you can have a variable called $sql that you continually reuse to store your different SQL commands.so:

$sql = "SELECT caseid FROM table001";//assuming you have already set $con$x = mysql_query($sql,$con);//rest of the code from above

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...