Computing.Net > Forums > Web Development > Simple PHP Question

Simple PHP Question

Reply to Message Icon

Original Message
Name: koolgirl
Date: April 1, 2006 at 09:36:00 Pacific
Subject: Simple PHP Question
OS: XP
CPU/Ram: 1924
Comment:

Hi Guys
I have 2 questions, I am sure that the person who can answer one of them will be able to answer the second too.
1. I use Dreamweaver to play around with my site and learn more. Everything goes good the only thing that I am still not able to solve is the Draw layer. I want to draw a layer that will keep its position on all resolution just like the rest of the site and tables etc. But for example if I draw a layer at the left of the page which contains all the home/bla bla bla buttons. I position it as:
<div id="Layer1" style="position:absolute; left:12px; top:33px; width:135px; height:255px; z-index:1"></div>
When I preview the page, it will not show exactly where I wanted it to be. Anyway after repositioning it little by little a few times, I get the result that I want. By as soon as I change the screen resolution, it displays again somewhere else. How can I make the layer keep its position just like a table would stay where it is?
2. I got MySQL installed on webserver. Am learning PHP now. I got a sample Database, containing, ID/Name/Email/Ph# fields. I can view the names of my contacts with my sample.php which contains the following code:
<?php
$dbcnx = @mysql_connect("xxxxx",
"xxxxx", "xxxxx");
if (!$dbcnx) {
echo( "

Unable to connect to the " .
"database server at this time.</P>" );
exit();
}
if (! @mysql_select_db("contacts") ) {
echo( "

Unable to locate the Database" .
"database at this time.</P>" );
exit();
}
?>

Here are all the contacts in our database: </P>
<BLOCKQUOTE>
<?php
$result = mysql_query(
"SELECT Name FROM contacts");
if (!$result) {
echo("

Error performing query: " .
mysql_error() . "</P>");
exit();
}
while ( $row = mysql_fetch_array($result) ) {
echo("

" . $row["Name"] . "</P>");
}
?>
</BLOCKQUOTE>
***************************
This shows me the names of all the contacts in rows. I want to display not just names, but also the remaining fields and want to be able to display them in a table with borders possibly different colors for different columns. How can I do it? PLEASE help me fast. Thanks in Advance!

(Oops, just saw the length of this post in post preview. I know it will take a long time for any of you to just read it, Sorryyyy!!!)


Report Offensive Message For Removal


Response Number 1
Name: Michael J (by mjdamato)
Date: April 1, 2006 at 16:38:02 Pacific
Subject: Simple PHP Question
Reply: (edit)

1) Positioning is an inherited attribute. So, if your DIV is inside a table, another div, etc. then it's positioing will be dependant upon that element. If you were to post a link to the site, then we could see how the div is used.

2) To "get" the remianing fields you will need to retrieve them with your SQL query. You will need to add the filed names EXACTLY as they are written in the database on this line:

$result = mysql_query(
"SELECT Name, Id, Email, Phone FROM contacts");

Then you need to add the results from that query to the code which displays the results. Here's how you can do that in a table:

Replace this:

while ( $row = mysql_fetch_array($result) ) {
echo("
" . $row["Name"] . "</P>");
}

With this:
echo "<table border='1'>";
// Create header row
echo "<tr>";
echo "<td>Id</td>";
echo "<td>Name</td>";
echo "<td>Email</td>";
echo "<td>Phone</td>";
echo "</tr>";
while ( $row = mysql_fetch_array($result) ) {
echo "<tr>";
echo "<td>".$row["Id"]."</td>";
echo "<td>".$row["Name"]."</td>";
echo "<td>".$row["Email"]."</td>";
echo "<td>".$row["Phone"]."</td>";
echo "</tr>";
}
echo "</table>";

As for giving it different colors and such you would just use standard HTML or CSS, but you need to add it into the PHP to be written into the page.

Michael J


Report Offensive Follow Up For Removal

Response Number 2
Name: koolgirl
Date: April 2, 2006 at 09:47:38 Pacific
Subject: Simple PHP Question
Reply: (edit)

Thanks Alot Mechael

It worked perfectly and is much more simple to understand now. Honestly speaking I hardly understood the other script but it worked a little bit, yours is much more simple and WORKS. Thanks again
Now again 2 questions If somebody can again make it simple for me PLEASSSSSSE!
With this script now the table shows me all the record from A=>Z and that makes it a very long list. How can I specify as suppose 20 records to display and then the next 20 and so on.
2nd about the layer question again, I dont have it on my page yet because it is not working as I want it to be, here is an example of what I want to do in dreamweaver and you can check it in browser in different resolutions. It displays totally different in dreamweaver and browser.
*************************
<body bgcolor="#666666">
<table width="100%" height="319" border="1">
<tr>
<td height="23"><div align="center">I
want the layer aligned under this text
</div></td>
</tr>
<tr>
<td height="266" align="center"><div id="Layer1" style="position:absolute; left:200px; top:42px; width:403px; height:255px; z-index:1; background-color: #FFFFCC; layer-background-color: #FFFFCC; border: 1px none #000000;">
<div align="center">

 </p>

 </p>

 </p>

<em><strong>It is the
same width as the text
</strong></em> </p>
</div>
<div align="center"></div>
</div></td>
</tr>
<tr>
<td><div align="center">Above
this text
</div></td>
</tr>
</table>
</body>
******************************
Many Thanks in Advance!


Report Offensive Follow Up For Removal

Response Number 3
Name: Michael J (by mjdamato)
Date: April 3, 2006 at 06:56:49 Pacific
Subject: Simple PHP Question
Reply: (edit)

You could try and build the logic to create pagination yourself, but I'd just use something that is already built. here is a class you can use for that: http://www.phpclasses.org/browse/package/1345.html

As for the div positioning, I don't know what what you are doing. Why are you creating div in two separate TD's that you want to be overlayed on top of each other? Put the divs in the same TD. As I stated above positioning is inherited, so the positioning *can* be dependant upon the element that the div happens to be in.

Michael J


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Simple PHP Question

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software