PHP question(not as complicated as you think)

  • Hacker007
  • Proficient
  • Proficient
  • User avatar
  • Joined: Apr 07, 2004
  • Posts: 371
  • Loc: Riverside, CA
  • Status: Offline

Post April 13th, 2004, 7:21 pm

Ok i have herd that it is possible to make a file on your server space then with php link that to your html document and make that text apperre. Is this possible. Becuase if you can just edit the file instead of editing the html i would be very happy, so please answer if you have one. :D
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post April 13th, 2004, 7:21 pm

  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Joined: Jun 15, 2003
  • Posts: 4583
  • Loc: Maryland
  • Status: Offline

Post April 13th, 2004, 7:26 pm

Yes, why indeed it is possible!

But your document can no longer be html, it must be saved as .php.

Go look up include over at http://www.php.net
Pixel Acres V2
  • buzzby365
  • Proficient
  • Proficient
  • No Avatar
  • Joined: May 14, 2004
  • Posts: 288
  • Status: Offline

Post May 17th, 2004, 6:18 pm

i am trying to make a submenu from text that has been pulled from a database. do you know how to do this?
  • BinaryTox1n
  • Beginner
  • Beginner
  • No Avatar
  • Joined: May 17, 2004
  • Posts: 55
  • Loc: Deer Park, Texas
  • Status: Offline

Post May 17th, 2004, 6:24 pm

its quite easy

PHP Code: [ Select ]
<?php
 
$query = mysql_query("SELECT * FROM links",$db);
 
while ($rowquery = mysql_fetch_array($query)){
 
       echo "<a href=\"$rowquery['linkurl']\">$rowquery['linktext']</a>";
 
}
 
?>
  1. <?php
  2.  
  3. $query = mysql_query("SELECT * FROM links",$db);
  4.  
  5. while ($rowquery = mysql_fetch_array($query)){
  6.  
  7.        echo "<a href=\"$rowquery['linkurl']\">$rowquery['linktext']</a>";
  8.  
  9. }
  10.  
  11. ?>


that example uses a table with 2 columns: linkurl and linktext
  • buzzby365
  • Proficient
  • Proficient
  • No Avatar
  • Joined: May 14, 2004
  • Posts: 288
  • Status: Offline

Post May 17th, 2004, 6:40 pm

is it possible to have many queries rtunning on a single page or just one query per page?

like for instance pagination which uses a database/table (i think) and data display from a sql table
  • BinaryTox1n
  • Beginner
  • Beginner
  • No Avatar
  • Joined: May 17, 2004
  • Posts: 55
  • Loc: Deer Park, Texas
  • Status: Offline

Post May 17th, 2004, 6:45 pm

You can have as many queries on a page as you like, but having bunches of open connections to the db isnt being nice to your server, so its good practice to close connections after you're done by using
PHP Code: [ Select ]
mysql_close([int link_identifier]);
where [int link_identifier] is the variable of your mysql connection.
  • buzzby365
  • Proficient
  • Proficient
  • No Avatar
  • Joined: May 14, 2004
  • Posts: 288
  • Status: Offline

Post May 17th, 2004, 6:57 pm

so at the end of the links query you posted up there for me, the last line can be:

mysql_close([int link_identifier]);


making the complete statement look like this:

PHP Code: [ Select ]
<?php
$query = mysql_query("SELECT * FROM links",$db);
while ($rowquery = mysql_fetch_array($query)){
    echo "<a href=\"$rowquery['linkurl']\">$rowquery['linktext']</a>";
}
mysql_close([int link_identifier]);
?>
  1. <?php
  2. $query = mysql_query("SELECT * FROM links",$db);
  3. while ($rowquery = mysql_fetch_array($query)){
  4.     echo "<a href=\"$rowquery['linkurl']\">$rowquery['linktext']</a>";
  5. }
  6. mysql_close([int link_identifier]);
  7. ?>


is that right?
  • buzzby365
  • Proficient
  • Proficient
  • No Avatar
  • Joined: May 14, 2004
  • Posts: 288
  • Status: Offline

Post May 18th, 2004, 3:34 am

a little confused. i understand this code:

echo "<a href=\"$row['LinkTarget']\">$row['LinkText']</a>";

but what i want is this.

the link button are as follows. A1, A2, A3, A4, A5, A6, A7 etc. these will be pulled from the database depending on what button is pressed. (there is also B1, B2, B3 etc.) now these buttons are also links to information that will appear in the row below. so A1 is a link for A1 information and so on up until A7.

i hope i am explaining this correctly. i have got the table for the buttons as follows:

Code: [ Select ]
CREATE TABLE link2text (
        id MEDIUMINT NOT NULL AUTO_INCREMENT,
        linkbutton VARCHAR(3) NOT NULL,
        linktarget VARCHAR(50) NOT NULL,
        linktitle VARCHAR(30) NOT NULL,
        linktext TEXT NOT NULL,
        PRIMARY KEY (id)
        )
  1. CREATE TABLE link2text (
  2.         id MEDIUMINT NOT NULL AUTO_INCREMENT,
  3.         linkbutton VARCHAR(3) NOT NULL,
  4.         linktarget VARCHAR(50) NOT NULL,
  5.         linktitle VARCHAR(30) NOT NULL,
  6.         linktext TEXT NOT NULL,
  7.         PRIMARY KEY (id)
  8.         )

linkbutton is the A1, A2....., A7. all these need to be in on row. not just A1 but all up to A7. these buttons will point to the target in linktarget to get the relative text in linktext.

i hope i have said this properly.
  • buzzby365
  • Proficient
  • Proficient
  • No Avatar
  • Joined: May 14, 2004
  • Posts: 288
  • Status: Offline

Post May 18th, 2004, 3:44 am

i basically want 1 row to contain all 7 buttons that are pulled from the database. and those 7 buttons link to textual information
  • buzzby365
  • Proficient
  • Proficient
  • No Avatar
  • Joined: May 14, 2004
  • Posts: 288
  • Status: Offline

Post May 18th, 2004, 6:40 am

i am really getting myself into a state here. the mock database that i wrote before worked fine. here is the code:

PHP Code: [ Select ]
<?php
$db=mysql_connect('localhost','root') or die('DB ERROR: Could not connect<br />');
mysql_select_db("danny",$db) or die('DB ERROR: Could not select DB');
$imageid = isset( $_GET['id'] ) ? $_GET['id'] : '';
//echo('Image ID "'.$imageid.'"<br />');
//$imageid; //contains the unique_id of the required image
$res=mysql_query("SELECT * FROM imageslinks WHERE imageid='$imageid'",$db) or die('DB ERROR: '.$sql.'<br />'.mysql_error().'<br />');
 
echo "<table border=1 cellpadding=1 cellspacing=0 bordercolor=#DBDBDB>";
echo "<tr><td><b>image</b></td><td><b>Name</b></td><td><b>Address</b></td></tr>";
 
echo "<tr><td>";
if($row=mysql_fetch_array($res, MYSQL_ASSOC)) {
 echo "<tr><td>";
 echo'<img src="http://localhost/images/'.$row["imageLink"].'">';
 echo "<td>";
echo $row["name"];
 echo "<td>";
echo $row["address"];
} else {
 echo('There are no rows to fetch');
}
echo "</td></tr></table>";
?>
 
  1. <?php
  2. $db=mysql_connect('localhost','root') or die('DB ERROR: Could not connect<br />');
  3. mysql_select_db("danny",$db) or die('DB ERROR: Could not select DB');
  4. $imageid = isset( $_GET['id'] ) ? $_GET['id'] : '';
  5. //echo('Image ID "'.$imageid.'"<br />');
  6. //$imageid; //contains the unique_id of the required image
  7. $res=mysql_query("SELECT * FROM imageslinks WHERE imageid='$imageid'",$db) or die('DB ERROR: '.$sql.'<br />'.mysql_error().'<br />');
  8.  
  9. echo "<table border=1 cellpadding=1 cellspacing=0 bordercolor=#DBDBDB>";
  10. echo "<tr><td><b>image</b></td><td><b>Name</b></td><td><b>Address</b></td></tr>";
  11.  
  12. echo "<tr><td>";
  13. if($row=mysql_fetch_array($res, MYSQL_ASSOC)) {
  14.  echo "<tr><td>";
  15.  echo'<img src="http://localhost/images/'.$row["imageLink"].'">';
  16.  echo "<td>";
  17. echo $row["name"];
  18.  echo "<td>";
  19. echo $row["address"];
  20. } else {
  21.  echo('There are no rows to fetch');
  22. }
  23. echo "</td></tr></table>";
  24. ?>
  25.  


this is fine for 1 row of information. but what if i have 3, 5 or 10 rows of information? how do i adapt this to th new situation?

with that code just posted, the php and the html were build up at the same time. for this project i am undertaking the html template has already been build. i now have to slot the php in. the rows of information is confusing me because i have so far only seen how 1 row can be build. is this where the 'asc' comes in to it? i am really not sure at all
  • BinaryTox1n
  • Beginner
  • Beginner
  • No Avatar
  • Joined: May 17, 2004
  • Posts: 55
  • Loc: Deer Park, Texas
  • Status: Offline

Post May 18th, 2004, 1:22 pm

ehm, im not sure i understand what you're trying to get at.
can you give me a html example of the output you want, so i can better understand?
  • buzzby365
  • Proficient
  • Proficient
  • No Avatar
  • Joined: May 14, 2004
  • Posts: 288
  • Status: Offline

Post May 18th, 2004, 5:36 pm

it needed to be a loop. i got the code.

it looks like this:

PHP Code: [ Select ]
if(mysql_num_rows($res) > 0)
{
while($row=mysql_fetch_array($res, MYSQL_ASSOC)) {
 echo "<tr><td>";
 echo $row["username"];
 echo "<td>";
echo $row["password"];
 echo "<td>";
echo $row["email"];
}
}else {
 echo('There are no rows to fetch');
}
 
  1. if(mysql_num_rows($res) > 0)
  2. {
  3. while($row=mysql_fetch_array($res, MYSQL_ASSOC)) {
  4.  echo "<tr><td>";
  5.  echo $row["username"];
  6.  echo "<td>";
  7. echo $row["password"];
  8.  echo "<td>";
  9. echo $row["email"];
  10. }
  11. }else {
  12.  echo('There are no rows to fetch');
  13. }
  14.  
  • BinaryTox1n
  • Beginner
  • Beginner
  • No Avatar
  • Joined: May 17, 2004
  • Posts: 55
  • Loc: Deer Park, Texas
  • Status: Offline

Post May 18th, 2004, 5:39 pm

roflmao, isnt that what i posted earlier? all you had to do was edit it....
  • buzzby365
  • Proficient
  • Proficient
  • No Avatar
  • Joined: May 14, 2004
  • Posts: 288
  • Status: Offline

Post May 18th, 2004, 5:57 pm

no offense. i had a difficult time trying to edit the code and trying to fit it in my template. 1 thing i have noticed is that when you build a php.mysql (html) page its ok coz u r starting from scratch. the dificulty is when you have the html template with all the tables already positioned, u then have to slot the php in. thats quite hard because at times you have to encapsulate the whole table into the php script for it to work and for the tables to actually do their job. i find that taxing and quite hard to get my head round. your coding looked like a generic sort of code but the one i am using was tailored to my situation. if i had more time and less hassle with my kids then i would have figured it out. as it is when you have 3 kids pullin at each leg plus an arm it only leaves you with one arm to type and do stuff.
  • buzzby365
  • Proficient
  • Proficient
  • No Avatar
  • Joined: May 14, 2004
  • Posts: 288
  • Status: Offline

Post May 18th, 2004, 6:24 pm

i am really stressing there, ready to pull my hair out. i have these scripts. by themselves they seem to work. but these scripts are suppose to be dependant on a button. u press a button then the info changes. if you have a whole load of generated info from queries when the page is id=1, what happenes to all the coding for id=2. i have no idea what i am doing anymore, being swallowed by code
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post May 18th, 2004, 6:24 pm

Post Information

  • Total Posts in this topic: 15 posts
  • Users browsing this forum: No registered users and 209 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.