Jump to content

Labels and values not appearing on the same line.


aquatradehub

Recommended Posts

Hi, I have this script which gets the info from the database and displays it in the page. It works fine apart from the Label and the result appearing on separate lines as if a <br /> tag was placed after the label. 

 

Here is the code

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);  

	include 'core/init.php';
	include 'includes/overall/header.php';
?>

<?php
$connect_error = 'Sorry, we are currently experiencing database issues. We are working to resolve this and should be up and running again shortly.';
$con=mysqli_connect('localhost', 'username', 'password', 'equatics_tropics');

if (isset($_GET['commonName']))
{
    $sCommonName = mysql_real_escape_string($_GET['commonName']);
    $sQry = "SELECT * FROM species WHERE commonName = '$sCommonName'"; 
    if ($qry = mysql_query($sQry))
    {
        while ($row = mysql_fetch_assoc($qry))
        {

vprintf('
<section id="content">
  <article id="index">
    <section class="index">
        <fieldset title="e-quatics.com">
        <legend></legend>
        <p><img src="../_images/tropical.png" height="250" width="250">Common Name: %s<br>
        Scientific Name: %s<br>
        Synonym: %s<br>
        Origin: %s<br>
        Size: %s<br>
        Environment: %s<br>
        Water Chemistry: %s<br>
        Temperature: %s<br>
        Feeding: %s<br>
        Sexing: %s<br>
        Compatability: %s<br>
        Temperament: %s<br>
        Breeding: %s<br>
        Comments: %s</p>
    </fieldset>            
</form>
    </section>
  </article>', $row);


			}
    }
}  
?>

And here is how it displays the information in the page

 

 

 

Common Name: 
Asian Arowana
Scientific Name: 
Scleropages formosus
Synonym: 
steoglossum formosum
Origin: 
Size: 16cm
Environment:
rivers

 

Instead of displaying it on the same line

eg. Common Name: Asian Arowana

Does anyone know how to fix this?

Thanks

Hi guys, thanks for your replies.  Firstly no, I am not using any divs with width restrictions and secondly, I changed the code to this

vprintf('
<section id="content">
  <article id="index">
    <section class="index">
        <fieldset title="e-quatics.com">
        <legend></legend>
        <p><img src="../_images/tropical.png" height="250" width="250">Common Name: %s
        Scientific Name: %s
        Synonym: %s
        Origin: %s
        Size: %s
        Environment: %s
        Water Chemistry: %s
        Temperature: %s
        Feeding: %s
        Sexing: %s
        Compatability: %s
        Temperament: %s
        Breeding: %s
        Comments: %s</p>
    </fieldset>            
</form>
    </section>
  </article>', $row[]."<br>");

and all I get is a Server Error :(

I have no idea, I was in discussion with another member and he suggested this. I dont understand the difference. What do I need to do to correct this?

 

Thanks

 

There are two different libraries.

 

Go to php.net and check out how to use mysqli or pdo. Stop using mysql!

and all I get is a Server Error :(

Hardly surprising as using [] in an expression like yours (and PravinS') will give a fatal error (ie $row[] . '<br>' ).

 

vprintf() takes an array as its argument, not a botched string.

Change:

$con=mysqli_connect('localhost', 'username', 'password', 'equatics_tropics');

to 

$con=mysql_connect('localhost', 'username', 'password') or die(mysql_error());

mysql_select_db('equatics_tropics') or die(mysql_error());

PS: Don't remove anything from your vsprintf function.

Just check how many arguments it takes, that's all I think.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.