0

I am displaying data from database in a table.
In the table I have tr tags and in the tr tag I have two td tags.

Here is code.

<table class="rag_table" rules="all">
<tr><th><font size="5">Technical Events</font></th><th><font size="5">Non-technical events</font></th></tr>
<?php
$query="SELECT id,name FROM event_content WHERE have_img=1";
$havepage=mysql_query($query);
$query1="SELECT id,name FROM event_content WHERE have_img=0";
$havepage1=mysql_query($query1);
?>
while ($row=mysql_fetch_array($havepage)) {
    ?>
    <tr><td><a href="robo_race.php?eve=eve$evt_id=<?php echo $row['id'];?>"><font color="#FC2B5F"><?php echo $row['name'];?></font></a></td>
    <?php
}
while ($row1=mysql_fetch_array($havepage1)) {
    ?>
    <td><?php echo $row1['name'];?></td></tr>
    <?php
}
?>
</table>

What I want exactly is that the left td tag must display the have_img=1 values and the right td tags must display the have_img=0 values. i want to display like...

enter image description here

Please help me.

0

3 Answers 3

3

Try this...

<table class="rag_table" rules="all">
    <tr>
        <th><font size="5">Technical Events</font></th>
        <th><font size="5">Non-technical events</font></th>
    </tr>
    <?php
    $query="SELECT id,name FROM event_content WHERE have_img=1";
    $havepage=mysql_query($query);
    $query1="SELECT id,name FROM event_content WHERE have_img=0";
    $havepage1=mysql_query($query1);
    while ($row=mysql_fetch_array($havepage))
    {
    ?>
        <tr>
            <td>
                <a href="robo_race.php?eve=eve$evt_id=<?php echo $row['id'];?>"><font color="#FC2B5F"><?php echo $row['name'];?></font></a>
            </td>
        <?php
        $check_right_td=0;
        while ($row1=mysql_fetch_array($havepage1))
        {
            ?>
            <td>
                <?php echo $row1['name'];?>
            </td>
        </tr>
        <?php
        $check_right_td=1;
        break;
        }
        if($check_right_td==0)
        {
        ?>
            <td></td>
        <?php
        }
    }
    ?>
</table>
Sign up to request clarification or add additional context in comments.

2 Comments

it is nice but it's breaking my table if there is not right td=left td.
or see image of result i want to like.
2

Try fetching data in one query instead of two, and try to manipulate in your loop,

$query="SELECT id,name FROM event_content"; // will get you have_img=1 and have_img=0

Let the query go and get results,

while($row=mysql_fetch_array($havepage)) {
    $res[] = $row; // collect the mysql data in array
}

Use condition as your application structure,

foreach($res as $record)
{
    // echo something common in both cases    

    if($record['have_img'] == 1)
    {
        // echo something for have_img=1
    }
    if($record['have_img'] == 0)
    {
        // echo something for have_img=0
    }
}

Comments

1
<table class = "rag_table" rules = "all">
<tr><th><font size = "5">Technical Events</font></th><th><font size = "5">Non-technical events</font></th></tr>
<?php
$query = "SELECT id,name,have_img FROM event_content WHERE have_img IN (0,1)";
$havepage = mysql_query($query);

while ($row = mysql_fetch_array($havepage)) {
    $leftTd = $rightTd = '';
    if ($row['have_img'] == 1) {
        $leftTd = $row['name'];
    } else {
        $rightTd = $row['name'];
    }
    ?>
    <tr>
        <td>
            <a href="robo_race.php?eve=eve$evt_id=<?php echo $row['id']; ?>">
                <font color="#FC2B5F"><?php echo $leftTd; ?></font>
            </a>
        </td>
        <td>
            <a href="robo_race.php?eve=eve$evt_id=<?php echo $row['id']; ?>">
                <font color="#FC2B5F"><?php echo $rightTd; ?></font>
            </a>
        </td>
    </tr>
    <?php
}
?>

2 Comments

it is display like if left td is there it won't display right td for that tr tag. i want it like see image that i just add.
I cannot find your image.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.