Jump to content

Recommended Posts

So I have a jobs database with the following columns: id, jobtext, jobdate, and id. This is how it looks right now: http://prahan.com/jobs/display.html.php

 

I have another table called author. In the authorid column in need the results of this query, SELECT name FROM author WHERE id = (SELECT authorid FROM job) , to be displayed for each row.

 

I also want to be able to customize the header title for each column.

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/211721-displaying-a-mysql-table-in-a-html-page/
Share on other sites

.....

I have another table called author. In the authorid column in need the results of this query, SELECT name FROM author WHERE id = (SELECT authorid FROM job) , to be displayed for each row.

 

I also want to be able to customize the header title for each column.

 

Thanks in advance!

 

The first thing that you should do is read in deep this

http://dev.mysql.com/doc/refman/5.0/en/join.html

 

after that the answer to your questions should be easy... just try :)

The first thing that you should do is read in deep this

http://dev.mysql.com/doc/refman/5.0/en/join.html

 

 

after that the answer to your questions should be easy... just try

 

Hmm.. can you give me some code examples that relate to my problem? Im a PHP beginner and that is pretty confusing..

Nevermind bout inserting it into the html page. This is the code i have.

 

<html><head><title>Available Jobs</title></head><body>
<?php
$db_host = 'localhost';
$db_user = 'root';
$db_pwd = 'pass';

$database = 'db';
$table = 'tb';

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");

// sending query
$result = mysql_query("SELECT job.id, jobtext, jobdate, name FROM job LEFT JOIN author ON author.id=job.authorid
");
if (!$result) {
    die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);

echo "<h1>Jobs:</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>$cell</td>";

    echo "</tr>\n";
}
mysql_free_result($result);
?>
</body></html>

 

How do I edit the code so i can customize the headers for each column?

 

Thanks

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.