Jump to content

Quick Question


jaybeeb

Recommended Posts

My SQL/PHP code is created, it displays to a table, but I want to display the actual values into a new table in a HTML file

 

Here is my SQL code

 

<?php

require_once 'library/db.php';


if (!($conn = mysql_connect('localhost', 'root', '')))
{
	showError();
}

if (!(mysql_select_db('itsupport', $conn)))
{
	showError();
}




if (!($result = mysql_query('select * from itsupport', $conn)))
{
	showError();
}


	while ($row =mysql_fetch_array($result))
{

	echo "<tr>";
	echo "<td>" . $row[user_Name] . "</td><td>" . $row[user_ID] . "</td><td>" . $row[staff_ID] . "</td><td>" . $row[Problem] . "</td><td>" . $row[Problem_ID] . "</td><td>"  . $row[user_email] . "</td><td>" . $row[staff_email] . "</td><td>" ;
	echo "<td><a href=\"update.php?id=$row[CId]\"><img border=\"0\" src=\"images/edit.gif\"></a>";
	echo "</tr>";
}

include 'library/closedb.php';

>

Link to comment
https://forums.phpfreaks.com/topic/100038-quick-question/#findComment-511582
Share on other sites

Try using variables for your table data first. It helps to organize.

<?php
$userName = $row[user_Name];
//ETC etc...
?>

If your going to echo each table row, I would suggest making it look something like this:

<?php
echo "<tr>";
echo "<td>" . $userName . "</td>";
echo "<td>" . $userID . "</td>";
echo "<td>" . $StaffID. "</td>";
.
.
yada yada
.
.
echo "</tr>";
?>

 

Are you receiving any errors or is the data not displaying? I don't know what your showError(); function does but I would suggest:

mysql_select_db('itsupport', $conn) or

      die("Could not select database:<br>" . mysql_error());

Until you get the feel for things unless your showError() function is more detailed.  Use the or die("blah blah" . mysql_error()) after everything.

 

Link to comment
https://forums.phpfreaks.com/topic/100038-quick-question/#findComment-511715
Share on other sites

Hi, Thanks for the tips,  changed it around a bit. Not getting any errors the data displays correctly in my PHP table I juts want to be able to call this table in a HTML file, is this possible?

 

Here is the code after I changed it arround, thanks

 

<table border="1">

<?php

require_once 'library/db.php';


if (!($conn = mysql_connect('localhost', 'root', '')))
{
	showError();
}

if (!(mysql_select_db('itsupport', $conn)))
{
	showError();
}

$User_Name = $row['User_Name'];
$User_ID = $row['User_ID'];
$Staff_ID =$row['Staff_ID'];
$Problem = $row['Problem'];
$Problem_ID = $row['Problem_ID'];
$User_email = $row['User_email'];
$Staff_email = $row['Staff_email'];


if (!($result = mysql_query('select * from itsupport', $conn)))
{
	showError();
}


	while ($row =mysql_fetch_array($result))
{

	echo "<tr>";
	echo "<td>" . $row[user_Name] . "</td>";
	echo "<td>" . $row[user_ID] . "</td>";
	echo "<td>" . $row[staff_ID] . "</td>";
	echo "<td>" . $row[Problem] . "</td>";
	echo "<td>" . $row[Problem_ID] . "</td>";
	echo "<td>" . $row[user_email] . "</td>";
	echo "<td>" . $row[staff_email] . "</td>";
	echo "</tr>";
}

include 'library/closedb.php';
?>
</table> 

Link to comment
https://forums.phpfreaks.com/topic/100038-quick-question/#findComment-511832
Share on other sites

Archived

This topic is now archived and is 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.