New php im working on... (in over my head LOL)

Ok, first off let me thank anyone taking the time to read my post. I really appreciate taking the time to see if you can help this ‘noob’. Also, I apologize if I posted this too many time, but I couldn’t determine if this was a true php question, or more of a database question, so I posted it in both threads.

I am not super new to any form of coding, but I am a master at none of them. Here is what I am doing.

I have a table in a MySQL(ver 5.5) and I have an e107 site which runs on the PHP Version 5.3.6 system. I have created a php application using NetBean that basically queries the table and returns the results in a nested table created by the php function(see code below).

[php]<?php
function SQLResultTable($Query)
{
$link = mysql_connect(localhost, UN, PW) or die('Could not connect: ’ . mysql_error()); //build MySQL Link
mysql_select_db(my_db) or die(‘Could not select database’); //select database
$Table = “”; //initialize table variable

$Table.= "<table border='2' style=\"border-collapse: collapse;\">"; //Open HTML Table

$Result = mysql_query($Query); //Execute the query
if(mysql_error())
{
    $Table.= "<tr><td>MySQL ERROR: " . mysql_error() . "</td></tr>";
}
else
{
    //Header Row with Field Names
    $NumFields = mysql_num_fields($Result);
    $Table.= "<tr style=\"background-color: #000066; color: #FFFFFF;\">";
    for ($i=0; $i < $NumFields; $i++)
    {    
        $Table.= "<th>" . mysql_field_name($Result, $i) . "</th>";
    }
    $Table.= "</tr>";

    //Loop thru results
    $RowCt = 0; //Row Counter
    while($Row = mysql_fetch_assoc($Result))
    {
        //Alternate colors for rows
        if($RowCt++ % 2 == 0) $Style = "background-color: #E7E7E7;";
        else $Style = "background-color: #8C9EC1;";
       
        $Table.= "<tr style=\"$Style\">";
        //Loop thru each field
        foreach($Row as $field => $value)
        {
            $Table.= "<td>$value</td>";
        }
        $Table.= "</tr>";
    }
    $Table.= "<tr style=\"background-color: #000066; color: #FFFFFF;\"><td colspan='$NumFields'>Query Returned " . mysql_num_rows($Result) . " records</td></tr>";
}
$Table.= "</table>";

return $Table;

}

//I call the function like this so it refreshes with new data everytime the page refreshes:
echo SQLResultTable(“SELECT Full_Name,Dept,Title,Phone,Image FROM e107_directory ORDER BY Full_Name asc”);
?>[/php]

The table returns just fine, however I want to add another column to that table. There is a field not displayed in the table currently that is present in my database that has a unique text string for each table entry of “employee_id.jpg”.

I want to have a 5th column in my table (last column) that adds a text string of ‘pic’ that would then be an href to \server\folder\employee_id.jpg so if you clicked on it and there was a file you would get an image of the person in a popup.

I assume the link can be assembled using concatenation of some form or another. I could also make the SQL table entry for ‘image’ hold the entire path if need be. My problem is I have no idea how to do this, or even if this is possible.

Can anyone point me in the right direction please? I would be forever grateful!

No ideas on this one?

If anyone needs a clearer understanding I can explain anything that is confusing again. Just give me the word.

give this way a try for getting all your records from the database and looping throihg them and linking to an image

[php]<?php
echo "<table border=‘2’ style=“border-collapse: collapse;”>

<tr style=“background-color: #000066; color: #FFFFFF;”>
Full Name
Dept
Title
Phone
Image

";

$sql = mysql_query("SELECT * FROM e107_directory ORDER BY Full_Name asc");
while($r = mysql_fetch_object($sql)) {	
	
	echo "<tr style=\"background-color: #8C9EC1\">"; 		
		echo "<td>$r->Full_Name</td>";
		echo "<td>$r->Dept</td>";
		echo "<td>$r->Title</td>";
		echo "<td>$r->Phone</td>";
		echo "<td><a href=\"$r->Image\" target=\"_blank\"></a> pic</td>";		
	echo "</tr>";		
}

echo "</table>";[/php]

Great, thanks for that snippit… I will get back to you once I have a chance to work with it a bit more…

Again, I really appreciate the help with this, its a great learning opportunity for me as well!

;D

I just did a test, and everything was really good. The only thing I had to do was change a little formatting to suit my preferences, and I had to move the closing anchor tag on to the other side of the ‘pic’ text and of course adjust my path concat as well.

You are simply amazing. I really appreciate the help I get from this community. Although this was my first post, I can usually lurk and find my answers without asking anyone…

Thanks again for the great support dave, you da man!

Sponsor our Newsletter | Privacy Policy | Terms of Service