Results 1 to 7 of 7
  1. #1
    pph Expert! Gordon's Avatar
    Join Date
    January 18th, 2005
    Location
    Edmonton Canada
    Posts
    5,781
    Can anyone help me here with a bit of php script please?

    I want to call some fields from my database using php, but if there is nothing in the field I dont want the rest of the text to print, for eg. pretend I want to call a field called "color", I want to do it so the if there is a value in the "color" field the script will print "get the (and the color value)" but if there is no value in the "color" field I don't want the "get the" to print.

    I hope someone can understand what I mean.
    One day parasites and their ilk will be made illegal, I bet a few Lawyers will be pissed off when the day comes.
    Mr. Spitzer is fetching it nearer

    YouTrek

  2. #2
    ABW Ambassador Greg Rice's Avatar
    Join Date
    January 18th, 2005
    Location
    Ohio
    Posts
    4,889
    If I understand you, then I use something similar for a free shipping field. It checks to see if shipping is equal to 0.00 and if that's true is says something like "Free Shipping". If that field (Shipping) has any value but 0.00 it doesn't display Free Shipping. If that's what you want try this:

    <?php
    if ($Query->Fields('Color') != '') {
    ?> get the <?php echo $Query->Fields('Color'); ?>
    <?php
    }
    ?>
    Greg Rice Affiliate Program Management
    www.gocmc.com info(AT)gocmc.com | 330-259-1223

    Join us! - MiNeeds.com | DiscountCandleShop/CheeseSupply | Feng Shui Plaza

  3. #3
    pph Expert! Gordon's Avatar
    Join Date
    January 18th, 2005
    Location
    Edmonton Canada
    Posts
    5,781
    Thanks for your reply Xandman but I keep getting this error. Do you have any idea what I am doing wrong please?

    Fatal error: Call to a member function on a non-object in /home/homemain/public_html/a.php on line 12
    One day parasites and their ilk will be made illegal, I bet a few Lawyers will be pissed off when the day comes.
    Mr. Spitzer is fetching it nearer

    YouTrek

  4. #4
    ABW Ambassador Greg Rice's Avatar
    Join Date
    January 18th, 2005
    Location
    Ohio
    Posts
    4,889
    Without seeing the code, it sounds like your script is requesting something from the database that doesn't exist. I've seen that error when, for example, I delete a query but don't get all the parts of it. So if I forgot to remove the closing code <?php $Query->Close(); ?> after I deleted the query I get that error. Basically, you're calling something in the database that isn't there. In the example above, the error was caused because I tried to close a query that wasn't defined-can't close $Query if it's not there.

    Does this make sense?
    Greg Rice Affiliate Program Management
    www.gocmc.com info(AT)gocmc.com | 330-259-1223

    Join us! - MiNeeds.com | DiscountCandleShop/CheeseSupply | Feng Shui Plaza

  5. #5
    pph Expert! Gordon's Avatar
    Join Date
    January 18th, 2005
    Location
    Edmonton Canada
    Posts
    5,781
    I am using this for the reason if there is no image I do not want an empty box with a red square.
    This script gets the images just fine but when there is no image I get the dreaded red x and empty image box, please tell me what I am doing wrong.
    Thanks in advance for any help

    $sql = mysql_query("SELECT image1, image2, image3 from table where productname = 'i'") or die(mysql_error());


    if((($image1 == ''))){
    echo "<a href=/ring_L1.php?i=$i><img src=\"$i/1.jpe\" width=200 alt=\"$productname\"><BR>Click for larger image</a><P>";
    } else {
    echo "";
    }



    if((($image2 == ''))){
    echo "<a href=/ring_L2.php?i=$i><img src=$i/2.jpe width=200 alt=$productname><BR>Click for larger image</a><P>";
    } else {
    echo "";
    }



    if((($image3 == ''))){
    echo "<a href=/ring_L3.php?i=$i><img src=$i/3.jpe width=200 alt=$productname><BR>Click for larger image</a><P>";
    } else {
    echo "";
    }
    One day parasites and their ilk will be made illegal, I bet a few Lawyers will be pissed off when the day comes.
    Mr. Spitzer is fetching it nearer

    YouTrek

  6. #6
    ABW Ambassador
    Join Date
    January 18th, 2005
    Posts
    551
    $sql = mysql_query("SELECT image1 from table where productname = 'i'");

    $row = mysql_fetch_array($sql);

    if ($row['image1']!=''){
    do whatever
    }


    if you have multiple rows then:


    $sql = mysql_query("SELECT image1 from table where productname = 'i'");

    while($row = mysql_fetch_array($sql)){

    if ($row['image1']!=''){
    do whatever
    }
    }

  7. #7
    ABW Ambassador Greg Rice's Avatar
    Join Date
    January 18th, 2005
    Location
    Ohio
    Posts
    4,889
    What Wayder said. It seems an "if" statement is the way to go:

    <?php
    if((($image1 == ''))){
    ?>

    <?php echo "<a href=/ring_L1.php?i=$i><img src=\"$i/1.jpe\" width=200 alt=\"$productname\"><BR>Click for larger image</a><P>"; {
    ?>

    <?php
    }
    ?>


    This way the code in between the "if" (<?php echo "<a href=/ring_L1.php?i=$i><img src=\"$i/1.jpe\" width=200 alt=\"$productname\"><BR>Click for larger image</a><P>"; {
    ?&gt would only show if the condition is true ($image1 == '') so you can put anything in between the IF statement. May not be the best way but it works for me.
    Greg Rice Affiliate Program Management
    www.gocmc.com info(AT)gocmc.com | 330-259-1223

    Join us! - MiNeeds.com | DiscountCandleShop/CheeseSupply | Feng Shui Plaza

  8. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. I have a question
    By bnorris10 in forum Commission Junction - CJ
    Replies: 1
    Last Post: January 17th, 2007, 01:43 PM
  2. Pixel Tracking Question.. (Tech Question)
    By CoolAffiliate in forum Midnight Cafe'
    Replies: 1
    Last Post: August 14th, 2006, 01:40 AM
  3. PR question
    By UncleScooter in forum Midnight Cafe'
    Replies: 7
    Last Post: July 20th, 2004, 02:18 PM
  4. One last question
    By ronwls in forum Midnight Cafe'
    Replies: 1
    Last Post: September 28th, 2003, 11:35 PM
  5. Replies: 3
    Last Post: April 29th, 2003, 06:31 AM

Posting Permissions

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