PDA

View Full Version : Photo Section with Text



Moshambi
09-17-2008, 07:01 AM
Just curious how I would go about making the text match an image...this is what I have so far but it doesn't add it to the last image...and also the text is the same for all the images, which I want to be different (or whatever the user supplies):



<?php

if($_SESSION['loggedIn'] == "true")
{
if($action == "edit")
{
require("conn.php");
$img_sql = "select imagefolder from users where username = '$user'";
$img_result = mysql_query($img_sql) or die ( mysql_error() );

$imgfolder = mysql_result($img_result, 0);

$images = glob('./images/' . $imgfolder . '/*.PNG');

$pictext = "select pictext from users where username='$user'";
$pictext_result = mysql_query($pictext) or die (mysql_error());
$pictext = mysql_result($pictext_result, 0);

$i = true;
?>
<table style="position: relative; left: 35px;">
<?php

foreach($images as $img)
{

if($i == true)
{
//echo "<img src='" . $img . "' style='margin: 0px 5px 0px 5px; border: 1px solid black;' /><br /><input type='text' />";
echo "<tr><td><img src='" . $img . "' style='margin: 0px 5px 0px 5px; border: 1px solid black;' /></td>";
echo "<td style='display: block; width: 150px;'>&nbsp;</td>";
}
else
{
echo "<td><img src='" . $img . "' style='margin: 0px 5px 0px 5px; border: 1px solid black;' /></td></tr>";
echo "<tr>
<td>
<p>
". $pictext . "
</p>
</td>
<td style='display: block; width: 150px;'>
&nbsp;
</td>
<td>
<p>" . $pictext ."
</p>
</td>
</tr>";
}

$i = !$i;
}
}
}


?>
</table>


Also I was wondering if there is a way to add an array-like field in MySQL, cuz I think that would help solve my problem. Thanks in advance!

Nile
09-18-2008, 01:23 AM
I don't thinking:


$i = !$i;

Makes $i false, if its true.

$i = true;
echo $i."<br />";
$i = !$i;
echo $i;

Moshambi
09-18-2008, 02:43 AM
right thats the check it makes to display an image row or a row that has the picture description. It works okay since I have it set up to be on every other row.

Nile
09-18-2008, 11:40 AM
So that means, this variable shouldn't display?
If thats the case, why not do:


unset($i); //unset the variable

Moshambi
09-18-2008, 01:16 PM
sorry I am still very new to PHP what does unset do? I'm guessing it deletes a variable after it's used..?

Nile
09-19-2008, 12:27 AM
It deletes a variable, whether or not its been used.