Jump to content

help getting fields from mysql


skis

Recommended Posts

I'm beginning to write an IT help request form to better learn how to interact with php and mysql. here is my code:

queue.php:

<?php
//queue for techs
require("connect.php");
$query  = "SELECT id, time, username, summary FROM itrequest";
$result = mysql_query($query);

while(list($id, $time, $username, $summary)= mysql_fetch_row($result))
{
    echo "<tr>" .
    "<td><input type=\"checkbox\" value=\"".$id."\" name=\"check".$id."\"></td>" .
    "<td>$id</td>" .
    "<td>$time</td>" .
    "<td>$username</td>" .
    "<td>$summary</td>";
}
---------------------------------------------------------------
ticket.php (where you go after you check the boxes next to the tickets you want to view and click submit button):

<?php
//used to view details of ticket(s)
require("connect.php");
$_POST = array_flip($_POST);
foreach($_POST as $checked => $box){
if($box != "NULL"){
$qid  = "SELECT id FROM itrequest WHERE id = $checked";
$qdate = "SELECT date FROM itrequest WHERE id = $checked";
$qusername = "SELECT username FROM itrequest WHERE id = $checked";
$qsummary = "SELECT summary FROM itrequest WHERE id = $checked";
$qdescription = "SELECT description FROM itrequest WHERE id = $checked";
$id = mysql_query($qid) or die("could not get id from mysql");
$thedate = mysql_query($qdate) or die("could not get date from mysql");
$username = mysql_query($qusername) or die("could not get username from mysql");
$summary = mysql_query($qsummary) or die("could not get summary from mysql");
$description = mysql_query($qdescription) or die("could not get description from mysql");
echo "Ticket ID: $id <br> Date: $thedate <br> Username: $username <br> Summary: $summary <br> Description: $description";
}
}
?>
------------------------------------------------------------------

Instead of getting Ticket #: <ticket number here>
I am getting Ticket #: Resource #16 and other numbers like that

Can anyone see what I am doing wrong?
Link to comment
Share on other sites

When you do a query, you're actually getting a reference to the results, you then have to process those results like so:

$id = mysql_query($qid) or die("could not get id from mysql");
$query = mysql_fetch_array($id);
$ticketNumber = $query["id"];
echo "Ticket Number: " . $ticketNumber;
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • 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.