portabletelly Posted May 29, 2007 Share Posted May 29, 2007 Im not sure if im using the right logic her but Im trying to output multiple rows of data which = techid in the data table. The mysql data table consits of the following columns CALL_ID ID FirstName EMail LastName cat_id descrip status priority phoneNumber phoneExt mobile ticketVisi pageView TechID cost Time_Logged I have a function which is displaying ques function display_Ques() { //conect to mysql and select db include("connect.php"); include("selectdb.php"); //define variables posted from ques.php $tech = htmlspecialchars($_POST['ChooseTech']); $customer = htmlspecialchars($_POST['ChooseCustomer']); //define sql get tech id query $query_get_tech_id = "SELECT id FROM accounts WHERE FirstName ='$tech'"; $result = mysql_query($query_get_tech_id, $link); if(mysql_num_rows($result)) { while($row = mysql_fetch_row($result)) { $techid = $row[0]; } } //Query all call for tech $query_get_calls ="SELECT * FROM data WHERE TechID ='$techid'"; echo "This is $tech Que"; echo '<br>'; echo "This is the Tech ID $techid"; echo '<table>'; $result_calls = mysql_query($query_get_calls, $link); if(mysql_num_rows($result_calls)) { while($row = mysql_fetch_row($result_calls)) { //echo the entire array here echo $row[0]; } } echo '</table>'; } ?> However I dont know what to do here to echo the text out in a nice format. while($row = mysql_fetch_row($result_calls)) { //echo the entire array here echo $row[0]; } Currently if I type in a different number between the [] the output will change to what ever is in the next colum where TechID ='$techid'. for example $row[0] shows the calls_ID 1234 where as $row[1] shows 4774 which is the values for ID (customers id). Can someone please point me in the right directions for what query I need to run to select all the calls WHERE FirstName ='$tech'"; and how I can output multiple colums into a table. Currently my select statment works however it the echo output which im having troubles with. Quote Link to comment https://forums.phpfreaks.com/topic/53404-echo-multiple-rows-from-mysql-query/ Share on other sites More sharing options...
Psycho Posted May 29, 2007 Share Posted May 29, 2007 Try this: <?php function display_Ques() { //conect to mysql and select db include("connect.php"); include("selectdb.php"); //define variables posted from ques.php $tech = htmlspecialchars($_POST['ChooseTech']); $customer = htmlspecialchars($_POST['ChooseCustomer']); //define sql get tech id query $query_get_tech_id = "SELECT id FROM accounts WHERE FirstName ='$tech' ORDER BY TechID"; $result = mysql_query($query_get_tech_id, $link); if(mysql_num_rows($result)) { $currentTechID = ""; echo "<table>"; while($row = mysql_fetch_row($result)) { if ($currentTechID!=$row[TechID]) { $currentTechID==$row[TechID]; echo "<tr><td colspan=\"99\"><b>Tech ID: $techid$currentTechID</b></td></tr>"; } echo "<tr>"; foreach ($row as $value) { echo "<td>$value</td>"; } echo "</tr>"; } echo '</table>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53404-echo-multiple-rows-from-mysql-query/#findComment-263876 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.