aquatradehub Posted August 3, 2013 Share Posted August 3, 2013 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 ArowanaScientific Name: Scleropages formosusSynonym: steoglossum formosumOrigin: Size: 16cmEnvironment:rivers Instead of displaying it on the same lineeg. Common Name: Asian ArowanaDoes anyone know how to fix this?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/280794-labels-and-values-not-appearing-on-the-same-line/ Share on other sites More sharing options...
PravinS Posted August 3, 2013 Share Posted August 3, 2013 remove "<br>" tag which are after label and try concatenating with $row as $row[]."<br>" Quote Link to comment https://forums.phpfreaks.com/topic/280794-labels-and-values-not-appearing-on-the-same-line/#findComment-1443326 Share on other sites More sharing options...
Barand Posted August 3, 2013 Share Posted August 3, 2013 Are you displaying inside a div with a width restriction? Quote Link to comment https://forums.phpfreaks.com/topic/280794-labels-and-values-not-appearing-on-the-same-line/#findComment-1443331 Share on other sites More sharing options...
aquatradehub Posted August 3, 2013 Author Share Posted August 3, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/280794-labels-and-values-not-appearing-on-the-same-line/#findComment-1443339 Share on other sites More sharing options...
jazzman1 Posted August 3, 2013 Share Posted August 3, 2013 Why are you using mysqli and mysql on the same script? Quote Link to comment https://forums.phpfreaks.com/topic/280794-labels-and-values-not-appearing-on-the-same-line/#findComment-1443341 Share on other sites More sharing options...
aquatradehub Posted August 3, 2013 Author Share Posted August 3, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/280794-labels-and-values-not-appearing-on-the-same-line/#findComment-1443342 Share on other sites More sharing options...
jazzman1 Posted August 3, 2013 Share Posted August 3, 2013 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! Quote Link to comment https://forums.phpfreaks.com/topic/280794-labels-and-values-not-appearing-on-the-same-line/#findComment-1443343 Share on other sites More sharing options...
Barand Posted August 3, 2013 Share Posted August 3, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/280794-labels-and-values-not-appearing-on-the-same-line/#findComment-1443346 Share on other sites More sharing options...
aquatradehub Posted August 3, 2013 Author Share Posted August 3, 2013 so any ideas how to fix the error of them not appearing on the same lines? Quote Link to comment https://forums.phpfreaks.com/topic/280794-labels-and-values-not-appearing-on-the-same-line/#findComment-1443348 Share on other sites More sharing options...
jazzman1 Posted August 3, 2013 Share Posted August 3, 2013 (edited) 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. Edited August 3, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/280794-labels-and-values-not-appearing-on-the-same-line/#findComment-1443349 Share on other sites More sharing options...
aquatradehub Posted August 3, 2013 Author Share Posted August 3, 2013 Thankyou, but should I not be using mysqli now or is it still ok to use mysql? Quote Link to comment https://forums.phpfreaks.com/topic/280794-labels-and-values-not-appearing-on-the-same-line/#findComment-1443355 Share on other sites More sharing options...
aquatradehub Posted August 3, 2013 Author Share Posted August 3, 2013 Also sorted my first prob. Just put the photo and the text in different fieldsets and it works great now Quote Link to comment https://forums.phpfreaks.com/topic/280794-labels-and-values-not-appearing-on-the-same-line/#findComment-1443356 Share on other sites More sharing options...
jazzman1 Posted August 3, 2013 Share Posted August 3, 2013 If you are new in php, don't waste your time learning the mysql library. This library is gonna be deprecated from a version 5.5 in php, I think. You should have start learning PDO or MySQLi. Quote Link to comment https://forums.phpfreaks.com/topic/280794-labels-and-values-not-appearing-on-the-same-line/#findComment-1443357 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.