Jump to content

Recommended Posts

Ok, I am new to both php and mysql so please bare with me. This is what I'm wanting to do..

 

I made a database that will return the results in a table. What I need help with is, in the one field name "type" it uses numbers to id the type of listing it is, 01, 02 and 03

 

What I want it to do is if the number is 01 I want it to show picture 01, if it's o2 I want it to show picture 02 if it's 03 I want it to show picture 3.

 

I can't get it to change this for each row that is pulled. I'm sure it's something easy but I can't get it to work. Any help at all would be GREAT!!!!

 

Thanks in advance.

-Joe

Link to comment
https://forums.phpfreaks.com/topic/40639-php-help-with-mysql-results/
Share on other sites

Can you post your current code?

 

here is what I have..

@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT * FROM equipmentlist";

$result=mysql_query($query);

\

$num=mysql_numrows($result);

?>

 

<?php

echo "<TABLE BORDER=\"0\" cellpadding\"0\" cellspacing=\"0\" width=\"100%\">\n";

echo "<tr width=\"100%\" bgcolor=\"#8383D5\"><td><font face=\"Arial\">Name</font></td><td><font face=\"Arial\">Type</font></td><td><font face=\"Arial\">Serial Number</font></td><td><font face=\"Arial\">In Service Date</font></td><td><font face=\"Arial\">Last Used By</font></td></tr>\n";

for($i = 0; $i < $num; $i++) {

    $row = mysql_fetch_array($result);

    if($i % 2) {

        echo "<TR bgcolor=\"ffffff\">\n";

    } else {

        echo "<TR bgcolor=\"E6E6E6\">\n";

    }

echo "<td>".$row['name']."</td><td>".$row['type']."</td><td>".$row['serialnum']."</td><td>".$row['inservice']."</td><td>".$row['lastused']."</td>\n";

    echo "</TR>\n";

}

echo "</TABLE>\n";

?>

 

I am very very very lost from here!  I'm sure the code is sloppy so please keep in mind I am brand new.

this is untested but may help

 

 

 

<?php

@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM equipmentlist";
$result=mysql_query($query);

$num= mysql_numrows($result);
?>

<?php
echo "<TABLE BORDER=\"0\" cellpadding\"0\" cellspacing=\"0\" width=\"100%\">\n";
echo "<tr width=\"100%\" bgcolor=\"#8383D5\"><td><font face=\"Arial\">Name</font></td><td><font face=\"Arial\">Type</font></td><td><font face=\"Arial\">Serial Number</font></td><td><font face=\"Arial\">In Service Date</font></td><td><font face=\"Arial\">Last Used By</font></td></tr>\n";

$i=true;
while ($row = mysql_fetch_array($result,MYSQL_NUM)) //loop all records
{
if($i)
{
	echo "<TR bgcolor=\"ffffff\">\n";
}else{
	echo "<TR bgcolor=\"E6E6E6\">\n";
}
echo "<td>".$row['name']."</td><td>".$row['type']."</td><td>".$row['serialnum']."</td><td>".$row['inservice']."</td><td>".$row['lastused']."</td>\n";
echo "</TR>\n";

$i = !$i; //reverses the value
}
echo "</TABLE>\n";
?>

this is untested but may help

 

Sorry, I really didn't understand that.. what I want to do is replace the value of one recordset (I guess thats the correct name) with 1 of 3 graphics. The first graphic is of a speaker to show that row is audio related. The next graphic is of a TV to show that row is video related and the last graphic is of a light to show that row is related to Lighting.

 

So while row 1 and row 2 come back with the type as "01" I want it to display graphic1 in place of "01". Row 3 and 5 may have the type value of "02" which would then display the TV graphic and row 4 may show the type as "03" which would then replace "03" with graphic 03.

 

I'm sure I'm not explaning this right...

Here is an example..

Name                        Type            Serial Number          In Service Date          Last Used By

EAW Vdocs Array 2      01                  12-3456789            03152006                  T.S.O.

Midias 50 Ch Mixer        01                  123456789            11162006                  NA

Sony 42" Plasma          02                  123456789            06212005                  Matell Toys

Martin Mac 500            03                  123456789            05292003                  M.H.S.

Sanyo PLC9000 Proj.    02                  123456789            02132003                  P and G Dev.

 

 

What I want to do is replace all the numbers in the "type" cat. with graphics.. so all of the 01's will use one graphic while 02 and 03 use a different..

 

I'm sorry I'm not explaning this right..

 

Thanks again for all your help.

ok this is how i would do it..

 

note the line

$images = array("01" => "path_to_image\image1.jpg", "02" => "path_to_image\image2.jpg", "03" => "path_to_image\image3.jpg", )    #<---------NEW

 

"01" => "path_to_image\image1.jpg"

01 = the  type

"path_to_image\image1.jpg" = a path to an image

 


<?php

@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM equipmentlist";
$result=mysql_query($query);

$num= mysql_numrows($result);
?>

<?php
echo "<TABLE BORDER=\"0\" cellpadding\"0\" cellspacing=\"0\" width=\"100%\">\n";
echo "<tr width=\"100%\" bgcolor=\"#8383D5\"><td><font face=\"Arial\">Name</font></td><td><font face=\"Arial\">Type</font></td><td><font face=\"Arial\">Serial Number</font></td><td><font face=\"Arial\">In Service Date</font></td><td><font face=\"Arial\">Last Used By</font></td></tr>\n";

$images = array("01" => "path_to_image\image1.jpg", "02" => "path_to_image\image2.jpg", "03" => "path_to_image\image3.jpg", )    #<---------NEW

$i=true;
while ($row = mysql_fetch_array($result,MYSQL_NUM)) //loop all records
{
if($i)
{
	echo "<TR bgcolor=\"ffffff\">\n";
}else{
	echo "<TR bgcolor=\"E6E6E6\">\n";
}
echo "<td>".$row['name']."</td>";
//echo "<td>".$row['type']."</td>";                                 #<-----------------OLD
echo "<td><img src='".$images[$row['type']]."' /></td>";    #<-----------------NEW

echo "<td>".$row['serialnum']."</td>";
echo "<td>".$row['inservice']."</td>";
echo "<td>".$row['lastused']."</td>\n";
echo "</TR>\n";

$i = !$i; //reverses the value
}
echo "</TABLE>\n";
?>

ok this is how i would do it..

 

note the line

$images = array("01" => "path_to_image\image1.jpg", "02" => "path_to_image\image2.jpg", "03" => "path_to_image\image3.jpg", )    #<---------NEW

 

"01" => "path_to_image\image1.jpg"

01 = the  type

"path_to_image\image1.jpg" = a path to an image

 

I bet that will work.. thanks so much!!!!

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.