Jump to content

echo problem


opel

Recommended Posts

I am working on a displaying a list of links in my admin system that I have entered into the Database. Each link is realted to a category that is in a separate table. I have written out an SQL statement that joins the 2 tables together however the variable information isn't writting out onto my page?

Can anyone see my error I'm determined to learn how to hand code PHP and stay away from Dreamweavers toolkit.

thanks for any help...

[code]<table>
<tr >
<th>Item Description</th>
<th>Category</th>
<th>Edit</th>
<th>Delete </th>
</tr>
<?php
include ('connections/config.php');
include ('connections/dbconn.php');

$query  = "SELECT tbl_links.link_id, tbl_links.link_title, tbl_links.link_desc, tbl_links.category_id, tbl_links.link_display, categories.category_name FROM tbl_links INNER JOIN categories ON tbl_links.category_ID = categories.category_name ORDER BY link_title";
$result = mysql_query($query) or die("error querying database");

$i = 0;
while($result_ar = mysql_fetch_assoc($result)){
?>
<tr <?php if($i%2 == 1){ echo "class='tablerow2'"; }else{echo "class='tablerow1'";}?>>
<td>
<?php echo $result_ar['link_title']; ?></td>
<td>
<?php echo $result_ar['category_name']; ?>
</td>
<td class="button">
<a href="edit_link_detail.php?ID=<?php echo $result_ar['link_id']; ?>" title="Edit This Link">Edit</a>
</td>
<td class="button">
<a href="delete_link.php?ID=<?php echo $result_ar['link_id']; ?>" title="Delete This Link">Delete</a>
</td>
</tr>
<?php
$i+=1;

                   
}?>
</table>[/code]
Link to comment
Share on other sites

Try this:
[code]<table>
<tr>
<th>Item Description</th>
<th>Category</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<?php

include 'connections/config.php';
include 'connections/dbconn.php';

$sql = "SELECT tl.link_id, tl.link_title, tl.link_desc, tl.category_id, tl.link_display, cats.category_name
        FROM tbl_links tl, categories cats
        WHERE tl.category_id = cats.category_name
        ORDER BY tl.link_title";

$result = mysql_query($sql) or die("Uable perform query at this time<br />" . mysql_error());

if(mysql_num_rows($result) > 1)
{
    $i = 0;
    while($result_ar = mysql_fetch_assoc($result))
    {
?>
<tr <?php echo (($i%2 == 1) ? "class='tablerow2'" : "class='tablerow1'"); ?>>
<td><?php echo $result_ar['link_title']; ?></td>
<td><?php echo $result_ar['category_name']; ?></td>
<td class="button">
<a href="edit_link_detail.php?ID=<?php echo $result_ar['link_id']; ?>" title="Edit This Link">Edit</a>
</td>
<td class="button">
<a href="delete_link.php?ID=<?php echo $result_ar['link_id']; ?>" title="Delete This Link">Delete</a>
</td>
</tr>
<?php
        $i++;
    }
}
else
{
    echo <<<HTML
<tr class="tablerow2">
<td style="color: red; font-weight: bold; text-align: center;">Sorry no results found</td>
</tr>
HTML;
}

?>
</table>[/code]
Link to comment
Share on other sites

thanks for the example I changed my sql statement to match up to the my table values and got this result: "sorry no results found"

here is my SQL statement :

"SELECT tbl_links.link_id, tbl_links.link_title, tbl_links.link_desc, tbl_links.category_id, tbl_links.link_display, categories.category_name
        FROM tbl_links, categories
        WHERE tbl_links.category_id = categories.category_name
        ORDER BY tbl_links.link_title";

have attached my tables SQL to and I have added further links to my DB version since then so there is definately content.




[attachment deleted by admin]
Link to comment
Share on other sites

Sorry I just saw your post just now change it to category id and some of wild teens code and it worked. here is correct SQL

[code]"SELECT tbl_links.link_id, tbl_links.link_title, tbl_links.link_desc, tbl_links.category_id, tbl_links.link_display, categories.category_name
       FROM tbl_links, categories
       WHERE tbl_links.category_id = categories.category_id
       ORDER BY tbl_links.link_title";[/code]
Link to comment
Share on other sites

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.