Jump to content

Echo multiple row's from mysql query


portabletelly

Recommended Posts

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.

Link to comment
Share on other sites

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>';
  }
}

?>

Link to comment
Share on other sites

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.