Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 8 of 8

Thread: setting image names with php

  1. #1

    setting image names with php

    Ok im querying the database and doing if statement on the name of a field, if name is this then set variable image to blank.gif. here is my code:

    PHP Code:
    <?php

    error_reporting
    (E_ALL & ~E_NOTICE);


    require_once(
    "connect2.php");

    $query "SELECT id, title, description, url, type, tutorial FROM design_main.urls WHERE (type = 'tutorial') OR (type = 'article') ORDER BY id DESC LIMIT 5"
    $result mysql_query($query) or die (mysql_error()); 
    $num mysql_num_rows($result);

    if(
    $row[5] = 'article'){
    $image 'article.gif';
    }
    elseif(
    $row[5] = 'photoshop'){
    $image 'ps.gif';
    }
    elseif(
    $row[5] = 'php'){
    $image 'php.gif';
    }

    echo
    "<table width=\"100%\" border=\"0\">";
    if(
    $num 0){
    while(
    $row mysql_fetch_array($resultMYSQL_NUM)){

    echo
    "<tr><td><span class=\"style2\" ><img src=images/$image>&nbsp;<b>$row[1]</b><br>$row[2]<br><i>$row[5]</i><br><br></span></td></tr>";
    }
    }
    else
    {
    echo
    '<span class="style1">The calendar is experiencing technical difficulties. We apologize for the inconvenience.</span>'
    }
    echo
    "</table>";

    ?>
    its hanging up on article and all my images are the article.gif. anyone see what im doing wrong?

  2. #2
    check this:
    if($row[5] = 'article')
    you are not comparing value, which is done with double equal sign :
    if($row[5] == 'article')

    what you are doing on all ifs and elses is assignation, not evaluation...

  3. #3
    remeber, that you're COMPARING, not SETTING variables!
    PHP Code:
    if ($row[5] == 'article') { 
       
    $image 'article.gif'
    } else if (
    $row[5] == 'photoshop') {
       
    $image 'ps.gif';
    } else { 
       
    $image 'php.gif'

    lol - twice the good answer

    [edit]neat code[/edit]

  4. #4
    yeah i had == signs earlier and it still wasnt working for some reason, let me try it again.

  5. #5
    ok i got this now and im getting no images at all

    PHP Code:
    <?php

    error_reporting
    (E_ALL & ~E_NOTICE);


    require_once(
    "connect2.php");

    $query "SELECT id, title, description, url, type, tutorial FROM design_main.urls WHERE (type = 'tutorial') OR (type = 'article') ORDER BY id DESC LIMIT 5"
    $result mysql_query($query) or die (mysql_error()); 
    $num mysql_num_rows($result);

    if(
    $row[5] == 'article'){
    $image 'article.gif';
    }
    elseif(
    $row[5] == 'photoshop'){
    $image 'ps.gif';
    }
    elseif(
    $row[5] == 'php'){
    $image 'php.gif';
    }

    echo
    "<table width=\"100%\" border=\"0\">";
    if(
    $num 0){
    while(
    $row mysql_fetch_array($resultMYSQL_NUM)){

    echo
    "<tr><td><span class=\"style2\" ><img src=images/$image>&nbsp;<b>$row[1]</b><br>$row[2]<br><i>$row[5]</i><br></span></td></tr>";
    }
    }
    else
    {
    echo
    '<span class="style1">The calendar is experiencing technical difficulties. We apologize for the inconvenience.</span>'
    }
    echo
    "</table>";

    ?>

  6. #6
    hi, this bunch of code :

    PHP Code:
    if($row[5] == 'article'){
    $image 'article.gif';
    }
    elseif(
    $row[5] == 'photoshop'){
    $image 'ps.gif';
    }
    elseif(
    $row[5] == 'php'){
    $image 'php.gif';

    must be inside the while { } otherwise when you try to evaluate the value of $row the array has not yet been created.

  7. #7
    ah ok that makes sense. Tried it and it works, thanks again pixel

  8. #8
    good to help you! happy coding

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012