Jump to content

Recommended Posts

I have a query below that gets its results and puts them in a table. The current results are from two fields in a db table. I am wondering if it is possible to create a second query to get results from a different db table and echo them out in the same html table as the ones already there? Many thanks. :)

 

        <?php
include_once  'functions.php';
loginDetails();
session_start();
	$query = "SELECT * FROM users ORDER BY id";

// execute query 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// see if any rows were returned 
if (mysql_num_rows($result) > 0) { 
    // yes 
    // print them one after another 
    echo "<table id=drtable>";
    echo "<tr><td><h2>Band ID</h2></td>";
echo "<td><h2>Band Name</h2></td></tr>"; 

    
while($row = mysql_fetch_assoc($result)) { 
	echo "<tr>";
        echo "<td><h2><a href=profile.php?bandid=".$row['id'].">".$row['id']."</a></h2></td>";
        echo "<td><h2><a href=profile.php?bandid=".$row['id'].">".$row['bandname']."</a></h2></td>"; 
        echo "</tr>";
    } 
    echo "</table>"; 
} 
else { 
    // no 
    // print status message 
    echo "No bands found."; 
} 
  ?>

Cheers I did it with a MySQL join. It seems to be working although images are not showing properly as the image locations are all getting %3c/a added on after the file extension. Has me baffled as to why this is happening, any ideas?

 

Full query with output

 

        <?php
include_once  'functions.php';
loginDetails();
session_start();
	$query = "SELECT users.id, users.bandname, images.path ".
	"FROM users, images ".
	"WHERE users.id = images.id";
	//$query = "SELECT * FROM users ORDER BY id";

// execute query 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// see if any rows were returned 
if (mysql_num_rows($result) > 0) { 
    // yes 
    // print them one after another 
    echo "<table id=drtable>";
    echo "<tr><td><h2>Band Image</h2></td>";
echo "<td><h2>Band Name</h2></td>";
echo "<td><h2>Band ID</h2></td></tr>"; 

    
while($row = mysql_fetch_assoc($result)) { 
	echo "<tr>";
        echo "<td><h2><a href=profile.php?bandid=".$row['id'].">","<img src=".$row['path']."</a></h2></td>";
	echo "<td><h2><a href=profile.php?bandid=".$row['id'].">".$row['bandname']."</a></h2></td>";
        echo "<td><h2><a href=profile.php?bandid=".$row['id'].">".$row['id']."</a></h2></td>"; 
        echo "</tr>";
    } 
    echo "</table>"; 
} 
else { 
    // no 
    // print status message 
    echo "No bands found."; 
} 
  ?>

Try this

 

<?php
echo "<td><h2><a href=profile.php?bandid='".$row['id']."'><img src='".$row['path']."'></a></h2></td>";

 

You didn't have quotes around your img path and also a closing ">" tag.

 

Let me know if that works.

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.