Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
MySQL table into HTML table problem
Old 11-18-2007, 05:21 PM MySQL table into HTML table problem
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
I am attempting to take a mysql table and put into a html table, which i can do, but now i want to link each result in the table to confirm.php?id=[result], but it displays like:

here is my page code:
PHP Code:
<?php
###################################
# File: index.php                 #
# Project: List Confirm System    #
# By: MeleFire                    #
# Copyright 2007                  #
###################################
// Call Global Config File
include("config.php");
//Call header file
include 'header.php';
//Set some more vars
$table='campouts';
//Now Display the campout list
mysql_connect($dbloc$dbuser$dbpass);
@
mysql_select_db($dbname) or die("Can't select database");

// sending query
$result mysql_query("SELECT * FROM {$table}");
if (!
$result) {
    die(
"Query to show fields from table failed");
}

$fields_num mysql_num_fields($result);
$url=mysql_result($result,$i,"id");

echo 
"<h1>List Of Campouts</h1>";
echo 
"<table border='1'><tr>";
// printing table headers
for($i=0$i<$fields_num$i++)
{
    
$field mysql_fetch_field($result);
    echo 
"<td>{$field->name}</td>";
}
echo 
"</tr>\n";
// printing table rows
while($row mysql_fetch_row($result))
{
    echo 
"<tr>";

    
// $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    
foreach($row as $cell)
        echo 
"<td><a href=listandconfirm.php?id=$url>$cell</a></td>";

    echo 
"</tr>\n";
}
mysql_free_result($result);
//Call Page Footer
include 'footer.php';
?>
melefire is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-18-2007, 07:30 PM Re: MySQL table into HTML table problem
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
OK
Remember to @mysql_connect too (you don't have it as such) my example below assumes opening tags and connections etc.
PHP Code:
$query = "select * from $table";
$result = mysql_query($query);
$fields_num = mysql_num_fields($result); ?>
<h1>List of Campouts</h1>
<table border="1"><tr>
<?php for($i=0;$i<$fields_num;$i++){
$fields =mysql_fetch_field($result,$i);
echo 
"<td>".$fields->name."</td>";
}
?></tr>
<?php $url=mysql_result($result,$i,"id"); /*This would print out the id column which makes me wonder what the $fields (headers) section is supposed to be printing out from how this is set up. Care to explain what it's for?*/
 
$rows_num mysql_num_rows($result);
for(
$i=0;$i<$rows_num;$i++){
//Now the $url will work ^_^
echo "<tr><td><a href=\"listandconfirm.php?id=".$url."\">cell".$i."</a></td></tr>";
// You may wish to change $url to be $row not $i if you are sure you want it your way
/*Sort of confused as to what your result would be here... this should at least output something, but without your SQL table structure I can't tell what you'd want...*/
}?></table>
Not as super correctly built as yours and I don't use that much tabbing, but it's readable and it should work just remember if you want more help post the Table structure, if you want to use your $row = thing try changing $url to be $row not $i.
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 11-19-2007, 04:35 PM Re: MySQL table into HTML table problem
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
That really helped, now i can get the url to work! but something strange happens, the ID table header disappears screwing everything up like this:

could someone help me?
melefire is offline
Reply With Quote
View Public Profile
 
Old 11-19-2007, 06:18 PM Re: MySQL table into HTML table problem
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
ok fixed that problem but now i just realized that all the links lead to listandconfirm.php?id=1, i need this link to be dynamic
melefire is offline
Reply With Quote
View Public Profile
 
Old 11-19-2007, 08:46 PM Re: MySQL table into HTML table problem
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
If I could see your table structure I could do this better.
Try this change though: put $url=mysql_result($result,$i,"id"); in the for loop. Don't know what I was thinking.
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 11-20-2007, 09:09 AM Re: MySQL table into HTML table problem
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
so where exactly do i put it?
melefire is offline
Reply With Quote
View Public Profile
 
Old 11-20-2007, 09:43 AM Re: MySQL table into HTML table problem
Super Talker

Posts: 134
Trades: 0
PHP Code:
<php  
 $rows_num 
mysql_num_rows($result);
for(
$i=0;$i<$rows_num;$i++){
$url=mysql_result($result,$i,"id");
echo 
"<tr><td><a href=\"listandconfirm.php?id=".$url."\">cell".$i."</a></td></tr>";
}
?> 
__________________

Please login or register to view this content. Registration is FREE

Check out the Facebook Clone build with Jcow SNS at
Please login or register to view this content. Registration is FREE
, it is free and it always will be
Falcone is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to MySQL table into HTML table problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25258 seconds with 12 queries