Hello i want to retrieve only one row from an mysqli statement.
The catch is that i use the $row=mysqli_fetch_array in a while() to loop the data. But i need a row to run as variable before the while begins

This is what i mean

$query=mysqli_query($db,"SELECT a_id,a_title,a_desc,a_url,a_img,a_uid,a_times FROM table WHERE status='1' ORDER BY a_id DESC ")or die(mysqli_error($db));
    $x=$query->fetchColumn(6)
    ?> <marquee behavior="scroll" loop="<?php echo $x;?>" scrollamount="4" direction="left" width="100%" height="50px"> <?php
    while($row=mysqli_fetch_array($query,MYSQLI_ASSOC))
    {
    echo  $row['a_url'].$row['a_title']. $row['a_desc'];
    }?> 

i want the $x variable to run the marquee but before the while. any suggestions?

Do you need that row in the following loop? If not then do:

$uid = mysqli_fetch_row($query, MYSQLI_ASSOC);
echo $uid[0]['a_uid'];

while($row = mysqli_fetch_assoc($query))
    # and so on

The loop will start from the second row in the result set. If you need that row in the loop then do:

$results = mysqli_fetch_all($query, MYSQLI_ASSOC);
$uid = $results[0]['a_uid'];

foreach($results as $row)
    # and so on

Another approach by using mysqli_data_seek():

# get first row
mysqli_data_seek($query, 0);
$uid = mysqli_fetch_row($query, MYSQLI_ASSOC);
echo $uid[0]['a_uid'];

# reset internal pointer
mysqli_data_seek($query, 0);

while($row = mysqli_fetch_assoc($query))
    # and so on

Besides, don't mix procedural with object, it won't work.

I understand but am very confused. The thing i want is for the <marqueee> to be looped as $x times as the a_times integer column has for value e.g. 5. Then i want the while to occure. But the marquee runs for infinite doesnt stop as $x times

$query=mysqli_query($db,"SELECT a_id,a_title,a_desc,a_url,a_img,to_uid_fk,times FROM advertisments WHERE status='1' ORDER BY a_id DESC ")or die(mysqli_error($db));

    $x = mysqli_fetch_row($query, MYSQLI_ASSOC);
echo $x[0]['times'];
    ?>
    <marquee behavior="scroll" loop="<?php echo $x;?>" scrollamount="4" direction="left" width="100%" height="50px">
    <?php
    while($row = mysqli_fetch_assoc($query))
    {
        $s = explode(",", $row['to_uid_fk']);
        foreach($s as $a)
        {
            if($profile_uid==$a)
            {?>

                <span>
                <b> <a href="<?php echo $row['a_url']; ?>"><?php echo $row['a_title']; ?></a></b> 
                <img border="0" src="<?php echo $base_url.$upload_path.$row['a_img']; ?>" 
                height="20px" width="30px" /> 
                <a href="<?php echo $row['a_url']; ?>"><?php echo $row['a_url']; ?></a>
                <?php echo $row['a_desc']; ?> <b style="color:#444; margin-left:10px;margin-right:10px">*</b> </span>
                <?php
            }
        }
    }
    ?>
</marquee>

the thing is that it runs for $x times for each $to_uid_fk

The loop attribute works fine for me with this test:

<marquee behavior="scroll" loop="2" scrollamount="4" direction="left" width="100px" height="170px">
    <span>abc</span>
    <span>def</span>
    <span>ghi</span>
</marquee>

Live example: http://jsfiddle.net/8uqatjed/

But consider that the marquee tag should NOT be used, as it is obsolete and not anymore supported by most recent browsers releases:

So, if I've understood good your request, this could be the reason it's not working well for you.

ok thanks again @cereal. You are the only one that understands me (just kidding)

Thats exactly what i am trying to void i dont want to loop <span>abc</span><span>def</span><span>ghi</span> the one under the other but in the same line. Not three lines. The one under the other works for me too. Thats what i ve trying to void all week.

Thats why i said i want the while after the marquee tag. Because it works this way. But i cant pass the variable to loop as many times as i want

I tried marquee with CSS3. the same results

Thats exactly what i am trying to void i dont want to loop <span>abc</span><span>def</span><span>ghi</span> the one under the other but in the same line.

To put them inline use span { display:inline-block; } or simply inline. However with the former you can set height, width, padding and margin properties:

did that before same thing

`

<marquee behavior="scroll" loop="<?php echo $x; ?>" scrollamount="4" direction="left" width="100%" height="50px">
        <span class="inline">
         <b><a href="<?php echo $data['a_url']; ?>"><?php echo $data['a_title']; ?></a></b> <img border="0" src="<?php echo $base_url.$upload_path.$data['a_img']; ?>" 
         height="20px" width="30px" /> <a href="<?php echo $data['a_url']; ?>"><?php echo $data['a_url']; ?></a><?php echo $data['a_desc']; ?></span>
         </marquee>

         .inline {
    display:inline-block;
    height:48px;
    width:48px;
    border:1px dotted gray;
    text-align:center;
    line-height:48px;
    margin:5px 0;
}

`

Maybe these are affected by other CSS rules. What happens if you isolate this portion and apply only his own rules?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.