Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

selecting data from a database with loops

Status
Not open for further replies.

mrobinson

MIS
Oct 11, 2002
36
GB
I am trying to print a list of information in a form from a database. The information i am wanting to print depends on the results from some froms and the takes a value from one table and the uses this value to find information from another table. is it possible to write a querey like this in SQL or do i need to use a loop in php to get the information. I have done the following php loops to try and do this but it doesn't seem to work and i can't make it work in a single SQL querey.

$x = $_POST[mod];
$y = $_POST[course];
$z = $_POST[sel_gp];


$get_list5 = "select stuid from student_group where stumg = '$z'";
$get_list_res5 = mysql_query($get_list5) or die(mysql_error());



while ($recs = mysql_fetch_array(get_list_res5)){

$group = $recs['stuid'];
$get_list6 = "select concat_ws(firstname, secondname) as display_name from student where stuid = $group";
$get_list_res6 = mysql_query($get_list6);

while ($recs2 = mysql_fetch_array(get_list_res6)){

$name = $recs2['display_name'];
$display_block .="$name";
}

}

Does anyone have any ideas for the best way for me to go about this??

much appriciated
 
after putting $ before all the get_list_res i executed the code and while it out put all the surnames it gave a repeated error in the sql code:

$get_list6 = "select concat_ws(firstname, secondname) as display_name from student where stuid = $group";

any ideas?
 
I assumed you were getting MySQL errors. But those of us who don't have your code and databases in front of them only speculate without knowing what exactly those MySQL errors are. Here goes anyway...

concat_ws() is concatenation with separators. The first parameter is the separator to be concatenated between all successive parameters. And I don't think that means much unless you have at least two additional parameters after the first, so that you can have two things to insert the first parameter between.

I don't know what kind of values you're trying to pass to MySQL via the variable $group. But unless they're numbers, you need single quotes around those values.

To speculate more wildly, the case sensitivity of table names depends on the case sensitivity of the filesystem on which MySQL is storing its tables. On unix-like OSes, if you create a table named "Foo", but later try to access it as "foo", MySQL will not recognize the table name. FAT32 on Win32 is more forgiving.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top