Page 1 of 1

displaying mysql data

Posted: Mon Oct 22, 2007 1:10 pm
by monkeymafia
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi

im trying to make a basic content management system. i can insert data into the mysql database via a html form no problem. 
just having a little difficulty displaying/retrieving the data.

When displaying the data i want it to be neatly formatted in a table, with the headings(which are fields from my mysql table): date created, memberid and subject. i want the subject to be a hyperlink to the record relating to the database contents. so when the subject is clicked it will take the user to the full contents of that listing displaying it in a form.

I have managed to get half way there. this is the code:

Code: Select all

<?php
include 'dbconnect.php';


// if no id is specified, list the available articles
if(!isset($_GET['ticketid']))
{
	$self   = $_SERVER['PHP_SELF'];

	$query  = "SELECT ticketid, subject, created FROM technicalproblems ORDER BY ticketid";
	$result = mysql_query($query) or die('Error : ' . mysql_error()); 
	
	// create the article list 
	$content =  '<ol>';
	while($row = mysql_fetch_array($result, MYSQL_NUM))
	{
		list($ticketid, $title) = $row;
		$content .= "<li><a href=\"$self?ticketid=$ticketid\">$title</a></li>\r\n";
	}
	
	$content .= '</ol>';
	
	$title   = 'Open Tickets';
} else {
	// get the article info from database
	$query   = "SELECT subject, message FROM technicalproblems WHERE ticketid=".$_GET['ticketid'];
	$result  = mysql_query($query) or die('Error : ' . mysql_error()); 
	$row     = mysql_fetch_array($result, MYSQL_ASSOC); 
	
	$title   = $row['ticketid'];
	$content = $row['message'];
}	

include 'dbclose.php';
?>
and this code is used to display the data once the subject is clicked:

Code: Select all

<html>
<head>
<title>
<?php echo $title;?>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
h1 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 18px;
	color: #006699;
	font-weight: bold;
}

.main {
	padding: 10px;
	border: 1px solid #006699;
	position: relative;
	width: 580px;
	margin-top: 20px;
	margin-bottom: 20px;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
-->
</style>
</head>
<body>
<table width="600" border="0" align="center" cellpadding="10" cellspacing="1" bgcolor="#336699">
 <tr> 
  <td bgcolor="#FFFFFF">

<h1 align="center"><?php echo $title;?></h1>
<?php 
echo $content;

// when displaying an article show a link
// to see the article list
if(isset($_GET['ticketid']))
{ 
?>
   <p>&nbsp;</p>
   <p align="center"><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Ticket list</a></p>
<?php
}
?>  

  </td>
 </tr>
</table>
</body>
</html>
ive tried messing around with the code all day long but no luck. ive got the basic concept working but any help and guidance
will be greatly appreciated. thanks in advance.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Oct 22, 2007 1:22 pm
by RobertGonzalez

Code: Select all

<?php
include 'dbconnect.php';

// Set a default ticket view flag
$showTicket = false;

// if no id is specified, list the available articles
if(!isset($_GET['ticketid']))
{
    // Change this
    //$self   = $_SERVER['PHP_SELF'];
    $self = basename(__FILE__);

    $query  = "SELECT ticketid, subject, created FROM technicalproblems ORDER BY ticketid";
    $result = mysql_query($query) or die('Error : ' . mysql_error());

    // create the article list
    $content =  '<ol>';
    while ($row = mysql_fetch_array($result))
    {
        $content .= "<li><a href=\"$self?ticketid=$row[ticketid]\">$row[title]</a></li>\r\n";
    }
    $content .= '</ol>';
       
    $title   = 'Open Tickets';
} else {
    // Change the showTicket flag
    $showTicket = true;

    // get the article info from database
    // THIS REALLY NEEDS TO BE CHECKED FOR VALIDATION
    $query   = "SELECT subject, message FROM technicalproblems WHERE ticketid=".$_GET['ticketid'];
    $result  = mysql_query($query) or die('Error : ' . mysql_error());
    $row     = mysql_fetch_array($result, MYSQL_ASSOC);
    $title   = $row['ticketid'];
    $content = $row['message'];
}       

include 'dbclose.php';
?>

Code: Select all

<html>
<head>
<title>
<?php echo $title; ?>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
h1 {
   font-family: Arial, Helvetica, sans-serif;
   font-size: 18px;
   color: #006699;
   font-weight: bold;
}

.main {
   padding: 10px;
   border: 1px solid #006699;
   position: relative;
   width: 580px;
   margin-top: 20px;
   margin-bottom: 20px;
   font-family: Arial, Helvetica, sans-serif;
   font-size: 12px;
}
-->
</style>
</head>
<body>
<table width="600" border="0" align="center" cellpadding="10" cellspacing="1" bgcolor="#336699">
 <tr>
  <td bgcolor="#FFFFFF">

<h1 align="center"><?php echo $title;?></h1>
<?php
echo $content;

// when displaying an article show a link
// to see the article list
if($showTicket)
{
?>
   <p>&nbsp;</p>
   <p align="center"><a href="<?php echo $self; ?>">Ticket list</a></p>
<?php
}
?> 

  </td>
 </tr>
</table>
</body>
</html>