Jump to content

[SOLVED] changing this to that


justAnoob

Recommended Posts

right now i have a line of code that says

<?php
echo '<img src="' . $row['imgpath2'] . '" width='125' alt="" />';
?>

 

I'm looking to put this in it's place....

<?php
if(mysql_num_rows($img2query) > 0)
{
echo '<img src="' . $row['imgpath2'] . '" width='125' alt="" />';
}
else
{
echo "No picture yet.";
}
?>

 

Can I echo an IF statement???

Link to comment
Share on other sites

What are you asking, justAnoob? Does your code not work? Or are you looking for something like this?

 

(mysql_num_rows($img2query) > 0) ? print "image src, etc...." : print "No picture yet.";

 

Link to comment
Share on other sites

keep getting error on this line.....

<?php
echo 'if(mysql_num_rows($img2query) > 0)
      {
      echo "<img src="' . $row['imgpath2'] . '" width='125' alt="" />";    // this line here
      }
      else 
      {
      echo "No picture yet."
      }';
?>

Link to comment
Share on other sites

Change width='125' to be width="125"

 

A simple syntax error. I would read up on PHP syntax and or invest in using a color coded PHP Editor. As that error really is plain to see.

 

EDIT:

You do realize that it will just print the actual statements. The smartass remark made about echoing if statements was because you chose your wording for the question very poorly.

 

<?php
if (mysql_num_rows($img2query) > 0) {
    echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" />';
}else {
    echo "No picture yet.";
}
?>

Link to comment
Share on other sites

smartass remark,,,, what are you talking about??? Does no one understand what I'm trying to do???

 

If you were being serious that you just want to "echo" and if statement then this would work:

 

<?php
echo 'if (mysql_num_rows($img2query) > 0) {
    echo \'<img src="' . $row['imgpath2'] . '" width="125" alt="" />\';
}else {
    echo "No picture yet.";
}';
?>

 

Notice that you had width='125' which was wrong because you were echoing inside of single quotes. Changing it to width="125" should fix that.

 

Are either of the solutions posted in Reply#6 or this reply the ones you are looking for? If not than no I do not understand at all what you are trying to do.

 

EDIT:

Fixed error.

Link to comment
Share on other sites

smartass remark,,,, what are you talking about??? Does no one understand what I'm trying to do???

 

If you were being serious that you just want to "echo" and if statement then this would work:

 

<?php
echo 'if (mysql_num_rows($img2query) > 0) {
    echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" />';
}else {
    echo "No picture yet.";
}';
?>

 

Notice that you had width='125' which was wrong because you were echoing inside of single quotes. Changing it to width="125" should fix that.

 

Are either of the solutions posted in Reply#6 or this reply the ones you are looking for? If not than no I do not understand at all what you are trying to do.

Syntax errors? And no, I personally have no idea what you want to do.

Link to comment
Share on other sites

I have a table that is echoed out with pictures in separate sections of the table....

Instead of just echoing the picture... like so

<?php
echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" />';
?>

I want a script in place of that echo saying that if the image is in mysql,, then show the image.... and if there is no image,, then say that there is no image.....

here is the rest of the script....

<?php
session_start();
include "connection.php";
$findit = $_SESSION['id'];
$result = mysql_query("SELECT id FROM members WHERE username = '$findit'");
$result = mysql_result($result, 0, 0);
$sql = mysql_query("SELECT imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return FROM member_trades WHERE user_id = '$result'");

$img2query = mysql_query("SELECT imgpath2 FROM member_trades WHERE user_id = '$result'");

echo "<table width='954' height='523' border='1' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#BBD4E1'>";
while ($row = mysql_fetch_array($sql))
{
echo "<tr><td width='188' height='180'><div align='center'>";
echo '<img src="' . $row['imgpath'] . '" width="125" alt="" />';
echo "</div></td><td width='188'><div align='center'>"; 

//echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" />';       //  this was the original line that I had but it did not work as I wanted it to... this line would return just a empty box with a red x in it if there was no picture in mysql database... 

if (mysql_num_rows($img2query) > 0)
{
echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" />';
}
else
{
echo "No picture yet."; 
}

echo "</div></td><td width='188'><div align='center'>";
echo '<img src="' . $row['imgpath3'] . '" width="125" alt="" />';
echo "</div></td><td width='188'><div align='center'>";
echo '<img src="' . $row['imgpath4'] . '" width="125" alt="" />';
echo "</div></td><td width='190'><div align='center'>";
echo '<img src="' . $row['imgpath5'] . '" width="125" alt="" />';
echo "</div></td></tr><tr><td height='43' colspan='4'>";
echo '<strong>Item Name:</strong> ' . $row['item_name'] . '';
echo "</td><td><div align='center'>";
echo "previouse next buttons";
echo "</div></td></tr><tr><td height='116' colspan='4'>";
echo '<strong>Description:</strong> ' . $row['description'] . '';
echo "</td><td><div align='center'>";
echo "</div></td></tr><tr><td height='124' colspan='4'>";
echo '<strong>Item wanted or price:</strong> ' . $row['in_return'] . '';
echo "</td><td><div align='center'>";
echo "</div></td></tr><tr><td colspan='4'>";
echo "save delete buttons";
echo "</td><td><div align='center'>";
echo "</td></tr>";
}
echo "</table>";
?>

Link to comment
Share on other sites

<?php
while ($row = mysql_fetch_array($sql))
{
echo "<tr><td width='188' height='180'><div align='center'>";
echo '<img src="' . $row['imgpath'] . '" width="125" alt="" />';
echo '</div></td><td width="188"><div align="center">
<?php     
if (mysql_num_rows($img2query) > 0)
{
echo "<img src="' . $row['imgpath2'] . '" width="125" alt="" />";
}
else
{
echo "No picture yet."; 
}
?>';
echo "</div></td><td width='188'><div align='center'>";
echo '<img src="' . $row['imgpath3'] . '" width="125" alt="" />';
echo "</div></td><td width='188'><div align='center'>";
echo '<img src="' . $row['imgpath4'] . '" width="125" alt="" />';
echo "</div></td><td width='190'><div align='center'>";
echo '<img src="' . $row['imgpath5'] . '" width="125" alt="" />';
echo "</div></td></tr><tr><td height='43' colspan='4'>";
echo '<strong>Item Name:</strong> ' . $row['item_name'] . '';
echo "</td><td><div align='center'>";
echo "previouse next buttons";
echo "</div></td></tr><tr><td height='116' colspan='4'>";
echo '<strong>Description:</strong> ' . $row['description'] . '';
echo "</td><td><div align='center'>";
echo "</div></td></tr><tr><td height='124' colspan='4'>";
echo '<strong>Item wanted or price:</strong> ' . $row['in_return'] . '';
echo "</td><td><div align='center'>";
echo "</div></td></tr><tr><td colspan='4'>";
echo "save delete buttons";
echo "</td><td><div align='center'>";
echo "</td></tr>";
}
echo "</table>";
?>

 

Can I have a script inside a script??

 

Link to comment
Share on other sites

calling this solved although it is not... It is driving me crazy.....

 

I got to this point... but it is still showing a box with a red x in it... When it should be saying "no picture here"

<?php
session_start();
include "connection.php";
$findit = $_SESSION['id'];
$result = mysql_query("SELECT id FROM members WHERE username = '$findit'");
$result = mysql_result($result, 0, 0);
$sql = mysql_query("SELECT imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return FROM member_trades WHERE user_id = '$result'");

$img2query = mysql_query("SELECT imgpath2 FROM member_trades WHERE user_id = '$result'");

echo "<table width='954' height='523' border='1' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#BBD4E1'>";
while ($row = mysql_fetch_array($sql))
{
echo "<tr><td width='188' height='180'><div align='center'>";
echo '<img src="' . $row['imgpath'] . '" width="125" alt="" />';
echo "</div></td><td width='188'><div align='center'>";

if (mysql_num_rows($img2query) > 0)
{
echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" />';
}
else
{
echo "No picture yet."; 
}

echo "</div></td><td width='188'><div align='center'>";
echo '<img src="' . $row['imgpath3'] . '" width="125" alt="" />';
echo "</div></td><td width='188'><div align='center'>";
echo '<img src="' . $row['imgpath4'] . '" width="125" alt="" />';
echo "</div></td><td width='190'><div align='center'>";
echo '<img src="' . $row['imgpath5'] . '" width="125" alt="" />';
echo "</div></td></tr><tr><td height='43' colspan='4'>";
echo '<strong>Item Name:</strong> ' . $row['item_name'] . '';
echo "</td><td><div align='center'>";
echo "previouse next buttons";
echo "</div></td></tr><tr><td height='116' colspan='4'>";
echo '<strong>Description:</strong> ' . $row['description'] . '';
echo "</td><td><div align='center'>";
echo "</div></td></tr><tr><td height='124' colspan='4'>";
echo '<strong>Item wanted or price:</strong> ' . $row['in_return'] . '';
echo "</td><td><div align='center'>";
echo "</div></td></tr><tr><td colspan='4'>";
echo "save delete buttons";
echo "</td><td><div align='center'>";
echo "</td></tr>";
}
echo "</table>";
?>

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.