1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Retrieve data SQL syntax error

Discussion in 'Databases' started by mirosoft1, Mar 18, 2018.

  1. #1
    Hello,
    Can you please correct the syntax error in this code
    
    if(mysqli_num_rows($sql) > 0)
        {
            while($row = mysqli_fetch_array($sql))
            {
                $result .='
                <tr>
                <td>'.$row["title"].'</td>
                <td>'.$row["name"].'</td>
                if($row["type"]==2)
                { echo "<td>type2</td>";}
                  else if($row["type"]==1)
                 {echo"<td>type1</td>";}
                 else if($row["type"]==3)
                 {echo"<td>type3</td>";}
               else if($row["type"]==4)
               {echo"<td>type4</td>";}
                <td>'.$row["add_date"].'</td>
                </tr>';
            }
        }
        else
    
    Code (markup):

    SEMrush
     
    mirosoft1, Mar 18, 2018 IP
    SEMrush
  2. sarahk

    sarahk iTamer Staff

    Messages:
    24,039
    Likes Received:
    3,238
    Best Answers:
    92
    Trophy Points:
    615
    #2
    this should do the trick

    if(mysqli_num_rows($sql) > 0)
        {
            while($row = mysqli_fetch_array($sql))  {
                $result .= "<tr>
                <td>{$row['title']}</td>
                <td>{$row['name']}</td>
                <td>type{$row['type']}</td>
                <td>{$row['add_date']}</td>
                </tr>";
            }
        }
        else
    PHP:
    If you need to add more logic around $row['type'] then use switch.
     
    sarahk, Mar 18, 2018 IP
  3. mirosoft1

    mirosoft1 Well-Known Member

    Messages:
    107
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    Thank you for your reply but if i want to change the echo "message" and type anything else like echo"Hello world" instead of "type 1"
    this solution didn't work for me.
     
    mirosoft1, Mar 19, 2018 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    24,039
    Likes Received:
    3,238
    Best Answers:
    92
    Trophy Points:
    615
    #4
    I'm not following you.

    I suspect you need to find some basic php tutorials and work through them.
     
    sarahk, Mar 19, 2018 IP