2 PHP questions (MySQL related)

sigmend

[H]ard|Gawd
Joined
Aug 6, 2003
Messages
1,303
Hey all, I have two questions.

I am pulling 3 columns from my MySQL database which I want displayed in a table. Three across and not limited down.
I want to hyperlink the text in the first column of boxes, with all different links...
For example, the first column of boxes will have a ticket number. I want to be able to click on that ticket number, and be taken to the corresponding ticket (Like if the number was 1234, and you clicked, it would take you to url://url?ticket=1234).


In this same table, different column...
Some of this data is numerical (1, 2, 3, and 4). Each number stands for something (Closed, Open, Resolved, Canceled).
How can I convert my numerical results to what it stands for?

I am probably not making any sense, I will clarify when people get confused.
 

lomn75

Purple Ace
Joined
Jun 26, 2000
Messages
6,613
I didn't bother to mirror the names precisely...

Code:
<?php 
// Assume you have queried to $result

while ($row = mysql_fetch_assoc($result)) {
    echo "<a href=\"/item.php?id=" . $row["uniqueid"] . "\">"
       . $row["uniqueid"] . "</a>";
    echo $row["otherthing"];
    switch ($row["status"])
    {
      case 0:
        echo "closed";
        break;
      case 1:
        echo "open";
        break;
      case 2:
        echo "b0rked";
        break;
      case 3:
        echo "pr0n";
        break;
    }
}
?>

incidentally, I swear by the CHM version of the PHP manual. Full index and text search integrated directly into my editor. This example format was a direct paste.
 

sigmend

[H]ard|Gawd
Joined
Aug 6, 2003
Messages
1,303
I can't get that to work, probably because don't know how to put that in a table, and I didn't give enough information in my original post.

Here is a snippet of code that I hope will help a little
JOB_TICKET_ID being Ticket. I want these hyperlinked
STATUS_TYPE_ID being Status. 1, 2, 3, 4. I want these translated into Closed, Open, Resolved, Canceled
SUBJECT being... subject.
PHP:
$Ticket_all = query("SELECT `JOB_TICKET_ID` , `STATUS_TYPE_ID` , `SUBJECT` FROM `job_ticket` WHERE `CLIENT_ID` ='$CLIENT_ID[0]'", $WHD_DB);


echo "<br>";
echo "<table border=1>";
echo "<td>Ticket</td>\n" ;
echo "<td>Status</td>\n" ;
echo "<td>Subject</td>\n" ;
echo "<tr>\n";

//now lots of crap I am confused about
 

lomn75

Purple Ace
Joined
Jun 26, 2000
Messages
6,613
look up mysql_fetch_assoc, as that has the full example that I pulled from (ex. 1).

To do the table, you'll have
Code:
<table>
  <tr><th>col 1</th><th>col 2</th><th>col 3</th></tr>
<?php while ($row=...)
{ 

   echo "<tr>...";

   // data-related code here

   echo "...</tr>";
} ?>
</table>
 

deuce868

Gawd
Joined
Feb 13, 2004
Messages
863
If you're storing the type as a int in the table just create an array like so:

Code:
$status = array();
$status[1] = "Open";
$status[2] = "Pending";
$status[3] = "Closed";

Then in your table you would use the int value passed in as the key and print out the text value.

Code:
print '<td>' . $status["$mysq_value"] . '</td>';
 

sigmend

[H]ard|Gawd
Joined
Aug 6, 2003
Messages
1,303
I asked a coworker today and he showed me something
Code:
SELECT job_ticket.job_ticket_id, status_type.status_type_name, job_ticket.subject FROM job_ticket job_ticket, status_type status_type WHERE job_ticket.client_id='$CLIENT_ID[0]' and job_ticket.status_type_id = status_type.status_type_id and job_ticket.status_type_id!=3 and job_ticket.status_type_id !=4 and job_ticket.status_type_id !=11;

We already had a table with the info in it, so somehow this pulled it.
Too bad I don't know what the hell is going on in that query.

Thanks anyway guys
 
Top