how do i display data as required

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

how do i display data as required

Post by chris_s_22 »

not exactly sure if this should even be in php section but i will ask anyways
I finally got my search page working however the result are then displayed on this blank page.

what im trying to achieve is to display the results on my searchindex.php
i can do a
include 'searchindex.php';
just before the
do
statement and the results would be displayed on that page. However i use css to display ever asspect of my page. and the results wouldnt be positioned correctly. i can add whats needed to my style.css however this page being fully php how do i wrap a div class around it
so when result is shown it will dispaly on the right page in the right position

Code: Select all

 
<?php
include 'Connect.php';
 
if(!isset($_GET[submit])) 
{
     // Show the form
     include 'searchindex.php';
     exit;
}
else
{
$result = mysql_query ("SELECT * FROM members WHERE username LIKE '%$searchone%' "); 
 
PRINT "<b>You searched for:</b> ";
PRINT "$searchone";
print ("<br>");
 
if ($row = mysql_fetch_array($result)) 
{ 
do 
{ 
PRINT "<b>User Name: </b> "; 
print $row["username"]; 
print (" "); 
print ("<br>"); 
PRINT "<b>Location: </b> "; 
print $row["location"]; 
print ("<p>"); 
PRINT "<b>Date of Birth: </b> "; 
print $row["dob"]; 
print ("<p>");
} 
while($row = mysql_fetch_array($result)); 
} 
else {print "Sorry, no records were found!";} 
}
?>
 
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: how do i display data as required

Post by califdon »

Just print (or echo) the tags you want. If you want a <div> tag, just:
print "<div>";
Print and echo merely send whatever follows to the browser.

You're already doing that with <b> and </b> tags, <div> is no different. By the way, <b> tags are deprecated. You should be using <strong> and </strong>. One of these days, the new browsers will not recognize deprecated syntax and your page will not render correctly.
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

Re: how do i display data as required

Post by chris_s_22 »

Code: Select all

PRINT ("<div class"searchresult">")
PRINT ("</div>")
include 'searchindex.php';
where would i put the above lines in the code if i do put
include 'searchindex.php';
that seems to be fine just before the "do" statement

ive tried putting the div tags in various positions but come up with the error

Code: Select all

Parse error: syntax error, unexpected T_STRING on line 22
also am i suposed to call the style sheet on this page as well? i do in the page i want to display the results on searchindex.php

i would of thought this would of been fine

Code: Select all

 
<?php
include 'Connect.php';
 
if(!isset($_GET[submit])) 
{
     // Show the form
     include 'searchindex.php';
     exit;
}
else
{
$result = mysql_query ("SELECT * FROM members WHERE username LIKE '%$searchone%' "); 
 
PRINT "<strong>You searched for:</strong> ";
PRINT "$searchone";
print ("<br>");
 
if ($row = mysql_fetch_array($result)) 
{ 
include 'searchindex.php';
PRINT ("<div class"searchresult">");
do 
{ 
PRINT "<strong>User Name:</strong> "; 
print $row["username"]; 
print (" "); 
print ("<br>"); 
PRINT "<strong>Location:</strong> "; 
print $row["location"]; 
print ("<p>"); 
PRINT "<strong>Date of Birth:</strong> "; 
print $row["dob"]; 
print ("<p>");
} 
PRINT "</div>";
while($row = mysql_fetch_array($result)); 
} 
else {print "Sorry, no records were found!";} 
}
?>
 
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: how do i display data as required

Post by jackpf »

Need to escape quotes.
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

Re: how do i display data as required

Post by chris_s_22 »

oh yeah i see what your getting at

PRINT ("<div class = searchresult>");
instead of using \ i found out just taking the quotes out works

this kinda works it positions perfect but thats when i put them inside the "do" statement. But as you can imagine because it loops it writes each result over the top of each other

ive tried a few places putting the print div tags outside but im getting errors or it mess the rest of page any id where the correct position should be?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: how do i display data as required

Post by jackpf »

I dont understand...are you using absolute positioning or something?
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

Re: how do i display data as required

Post by chris_s_22 »

yes im using something similar to this in style sheet
is this the problem what would be the work around?
position: absolute;
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: how do i display data as required

Post by jackpf »

Yeah, just don't use absolute positioning.
User avatar
timWebUK
Forum Contributor
Posts: 239
Joined: Thu Oct 29, 2009 6:48 am
Location: UK

Re: how do i display data as required

Post by timWebUK »

califdon wrote: By the way, <b> tags are deprecated. You should be using <strong> and </strong>. One of these days, the new browsers will not recognize deprecated syntax and your page will not render correctly.
I'm pretty sure <b> isn't deprecated... can't see it anywhere on the w3c specification. And also, if it was, I'm sure a style sheet using 'font-weight' would be a recommendation and not <strong>?
Post Reply