Jump to content


Photo

help getting fields from mysql


  • This topic is locked This topic is locked
2 replies to this topic

#1 skis

skis
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 20 October 2006 - 07:02 PM

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?

#2 tleisher

tleisher
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 20 October 2006 - 07:10 PM

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;

#3 skis

skis
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 20 October 2006 - 07:20 PM

thanks a lot, now it all makes sense




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users