PDA

View Full Version : Starting Site Based On Php


Paul
12-17-2001, 04:35 PM
Hi,
I am starting a site that will be based on php and mySQL. I hope it's allright for me to start this thread to get help in, this wont take up the board with a bunch of questions. For my first question I have this. I have a very simple code here:
<?

require "/home/thehotwe/www/php/header.php";
?>
<table border="0" cellpadding="0" cellspacing="2" width="100%">
<tr>
<td bgcolor="000000">
<table border="0" cellpadding="0" cellspacing="2" width="100%">
<tr>
<td bgcolor="FFFFFF">
<table border="0" cellpadding="0" cellspacing="2" width="100%">
<tr>
<td bgcolor="FFFFFF">
<?
$x = 1;
while ($x < $times) {

echo "<td>";

echo "<img src=\"http://fanaticnetwork.com/gallery/Actresses/Jennifer_Aniston/images/thumb/$x.jpg\"><br>";
echo "</td>";

++$x;
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
I need to know how to split the image results into colums in tables. Meaning I could set a variable with a number and this will be how many colums it will put the images in. For a working sample of the above code go to:
http://www.thehotweb.net/php/gallery.php?times=13
Thank You,
Paul

scoutt
12-17-2001, 05:30 PM
is $times always changing? and I am surprised this works ++$x;

suppose to be $x++;

also you could check $times to see if it is lower than a specific variable if it is then print out this table, but if it is bigger than print out this table. see what I'm getting at?

Paul
12-17-2001, 05:31 PM
Well what this will be is a picture gallery. Times will be allways changing but for now it is fine (gives me something to work with). Times is set up in the URL. And what I need is for it to split into 2 or 3 colums across a page. Thank you for your help.
Paul

Paul
12-17-2001, 09:29 PM
Any suggestions, maybe you could give me some pointers on this or a script that I can look at that does this?
Thank You,
Paul

scoutt
12-17-2001, 11:31 PM
try something like this, I haven't tested it but it should work in theory.


<?

require "/home/thehotwe/www/php/header.php";
?>
<table border="0" cellpadding="0" cellspacing="2" width="100%">
<tr>
<td bgcolor="000000">
<table border="0" cellpadding="0" cellspacing="2" width="100%">
<tr>
<td bgcolor="FFFFFF">
<table border="0" cellpadding="0" cellspacing="2" width="100%">

<?
$x = 1;
if ($times < 10){

while ($x < $times) {
echo"<tr> ";
for($i=0; $i<3; $i++){ //loops thru until 3 TD are made
echo"<td bgcolor=\"FFFFFF\"> ";
echo "<img src=\"http://fanaticnetwork.com/gallery/Actresses/Jennifer_Aniston/images/thumb/$x.jpg\"><br>";
$x++;
echo "</td>";
}
echo"</tr>";
$x++; // once done with cells, close TR and start over with new TR
</tr>
}

}else{ // if $times is greater than 10

while ($x < $times) {
echo"<tr> ";
for($i=0; $i<5; $i++){
echo"<td bgcolor=\"FFFFFF\"> ";
echo "<img src=\"http://fanaticnetwork.com/gallery/Actresses/Jennifer_Aniston/images/thumb/$x.jpg\"><br>";
$x++;
echo "</td>";

}
echo"</tr>";
$x++;

}

}
?>

</table>
</td>
</tr>
</table>
</td>
</tr>
</table>

Paul
12-19-2001, 08:50 AM
Thanks for the code scoutt, it looks like this will be it. There is a problem on line 27 and I can't figure out what it is. Any ideas?
Thanks,
Paul

scoutt
12-19-2001, 10:05 AM
there looks to be an extra <tr> tag. take it out. I thyink that is line 28, if not show me wha tyou got so far.

Paul
12-19-2001, 05:01 PM
Oops I read line 17 instead of 27, it works perfectly now. Thank you for your help. I will now play around to split this into pages.
Thank You,
Paul

scoutt
12-19-2001, 05:42 PM
it actually works???? can I see a test page or something.

Paul
12-20-2001, 08:28 AM
Yeah it's the link above, if you want more of a sample then replace 13 with 30 so it will look like this:
http://www.thehotweb.net/php/gallery.php?times=30
Also it's great to have a great programmer like you here. There are somethings there that I have just been playing with but everything works. Dont pay attention to the right menu as I was just testing on how to get results from mySQL.
Thanks,
Paul

scoutt
12-20-2001, 10:20 AM
looks good , thanks Paul :)

Paul
12-21-2001, 04:24 PM
Ok so far it's going great, I will soon be putting everything in nice little categories. Can someone try to add their link on the side to see if everything works. Here is the new URL:
http://www.fanaticnetwork.com/php/gallery.php?times=30
After you add you will propably get a blank page, just hit your back button twice and then refresh. Also these links wont be there very long but I need some to be able to play around with the way it outputs it.
Thanks,
Paul

scoutt
12-21-2001, 05:42 PM
ok I added mine and when I went back to view it on the front page it showed the url as in a directory. also need to have it so on the description is a textarea and what is title? title of me ot the site? just the little things.

Paul
12-21-2001, 05:46 PM
Originally posted by scoutt
ok I added mine and when I went back to view it on the front page it showed the url as in a directory. also need to have it so on the description is a textarea and what is title? title of me ot the site? just the little things.
Thanks scoutt. So far this is only testing code out so that is why it's so "cheap", I will add those in the final copy.
Thank You,
Paul

Paul
12-25-2001, 01:54 PM
Does anybody know what it wrong with this code? The error it gives me is this:

Warning: Unable to jump to row 1 on MySQL result index 3 in /home/fanaticn/public_html/php/gallery.php on line 28


<?

require "/home/fanaticn/www/php/header.php";
?>
<?
$username="fanaticn_paul";
$password="xxxx";
$database="fanaticn_counter";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts WHERE 1 ORDER BY title DESC";
$querypic="SELECT * FROM pictures WHERE id='$id' ORDER BY id DESC";
$result=mysql_query($query);
$resultpic=mysql_query($querypic);
$num=mysql_numrows($result);
mysql_close();
?>
<table border="0" cellpadding="0" cellspacing="2" width="100%">
<tr>
<td bgcolor="000000">
<table border="0" cellpadding="0" cellspacing="2" width="100%">
<tr>
<td bgcolor="FFFFFF" width="70%" valign="100%">
<table border="0" cellpadding="0" cellspacing="2" width="100%">

<?
$z=1;
$idpic=mysql_result($resultpic,$z,"id");
$catnamepic=mysql_result($resultpic,$z,"catname");
$picspic=mysql_result($resultpic,$z,"pics");

$x = 1;
if ($picspic < 10){

while ($x < $picspic) {
echo"<tr> ";
for($i=0; $i<4; $i++){ //loops thru until 3 TD are made
echo"<td bgcolor=\"FFFFFF\"> ";
echo "<img src=\"http://fanaticnetwork.com/gallery/Actresses/Jennifer_Aniston/images/thumb/$x.jpg\"><br>";
$x++;
echo "</td>";
}
echo"</tr>";
$x++; // once done with cells, close TR and start over with new TR

}

}else{ // if $times is greater than 10

while ($x < $picspic) {
echo"<tr>";
for($i=0; $i<4; $i++){
echo"<td bgcolor=\"FFFFFF\"> ";
echo "<a href=\"http://fanaticnetwork.com/gallery/Actresses/Jennifer_Aniston/images/$x.jpg\">";
echo "<img src=\"http://fanaticnetwork.com/gallery/Actresses/Jennifer_Aniston/images/thumb/$x.jpg\" border=\"0\"></a><br>";
$x++;
echo "</td>";

}
echo"</tr>";
$x++;

}

}
?>
</table>
</td>
<td width="30%" bgcolor="#ffffff" valign="top">
<table width="100%">
<tr>
<td width="100%" bgcolor="#ffffff" valign="top">


<tr>
<font face="verdana" size="2"><b>Links (<? echo "$num"; ?>)
</b></font>
</tr>
<tr>
<?


$i=0;
while ($i < $num) {

$url=mysql_result($result,$i,"url");
$title=mysql_result($result,$i,"title");
$description=mysql_result($result,$i,"description");

echo "<b><font face=\"verdana\" size=\"1\"><a href=\"$url\">$title</a><br>$description</font></b><br>";

++$i;
}

?>
<tr>
<a href="http://www.fanaticnetwork.com/php/open.htm"><font face="verdana" size="2">Add A Site</a></font>
</tr>
</tr>
</td>
</td>
</tr>
</tr>
</table>
</td>
</tr>
</table>

Thank You,
Paul

torrent
12-26-2001, 05:47 AM
Originally posted by hacker
[B]Does anybody know what it wrong with this code? The error it gives me is this:

Warning: Unable to jump to row 1 on MySQL result index 3 in /home/fanaticn/public_html/php/gallery.php on line 28



I'm just on my way out the door so apologies if this is totally wrong because I haven't had the chance to view the code in detail. Try looking here though for the answer, sounds like this could be root cause of the problem.

http://www.php.net/manual/en/function.reset.php

torrent
12-26-2001, 12:27 PM
Hacker, Paul, whatever, ;)

I just got back and took a look at your code. Disregard my previous post.

I think the problem maybe that you are only returning a single row but you have set the mysql_result() index ($z) to 1 instead of 0 (0 is the first row).

Are you sure that you want to use mysql_result() as opposed to mysql_fetch_row() or mysql_fetch_array(), which are deemed to be quicker?

Hope this helps. :)

Paul
12-26-2001, 06:46 PM
That did it, thank you very much.
Paul

Paul
12-31-2001, 08:20 PM
Ok I am almost finished with all this. The last think to do is split the above pictures up to pages. I have tried the Limit function in mySQL but the pictures are not setup in rows. My guess is that I will have to use foreach statements but the problem is that I really suck at them. Any suggestions?
Thank You,
Paul

scoutt
01-01-2002, 12:57 PM
so you are looking for a script to detect if there are so many pictures on the page go to another page, like next links?

Paul
01-01-2002, 01:31 PM
Exactly. I thought I could simply use the LIMIT query in mySQL but the pictures are not in rows. Do you have maybe an example or a solution? Thank you very much for your help scoutt. Also I should be done with The Hot Web soon and should be ready to exchange links with you.
Thanks,
Paul

Tom
01-01-2002, 01:54 PM
Originally posted by hacker


<?

require "/home/fanaticn/www/php/header.php";
?>
<?
$username="fanaticn_paul";
$password="xxxx";
e>



:eek: an XXX site eh? :D

scoutt
01-01-2002, 02:37 PM
he he :D

I don't think so Tom :D

I do have a script that will do what you want but it is a little difficult to impliment. let me see where I put it.

Paul
01-01-2002, 03:29 PM
Hmm... I found this tutorial on your site but still I dont know how to convert it to use my system. Like I said I am really bad at for() and foreach() statements.
http://hotwired.lycos.com/webmonkey/01/27/index3a_page5.html?tw=programming
Thanks,
Paul

scoutt
01-01-2002, 05:39 PM
I have another one that I haven't put on my site yet.
this is what I used and converted most of it to my site. if you have any trouble feel free to ask. just study it and it should make since.



//this is the main page

$number_of_ads_per_page = 10;

if(!$num_links2){ //only the first time through, otherwise it is in the next 15 button
$num_links2 = '0';
}
if ($num_links2 < 1 ): // do not reset offset unless a new search
if ($offset == 0 ):
$offset = '0'; // The default offset is zero
endif;
endif;


$comma = ",";
$limitq = "LIMIT " . $offset . $comma . $number_of_ads_per_page;
//sql_links2 is for the Previous and next link generator
$sql_links = "select * from $tbl where $whatever order by $order desc $limitq";// this is the one that sets the limit
$sql_links2 = "select * from $tbl where $whatever order by $order "; //same select without limit
$sql_result = mysql_query ($sql_links);
$sql_result2 = mysql_query ($sql_links2);
$num_links = mysql_num_rows($sql_result);
// if offset is 0 then use the num_links2, if offset
//is more than 0 it just by passes it.
if($offset == 0){
$num_links2 = mysql_num_rows($sql_result2);
}
$resultmax = $offset + $number_of_ads_per_page; // assign the outer result range number
if ( $resultmax > $num_links2 ):
$resultmax = $num_links2;
endif;
$firstrowonpage = $offset + 1;

// The function returns one and on column.

echo "<tr><td colspan=\"2\"><b>Total: $num_links2 &nbsp;&nbsp;&nbsp;Showing Results $firstrowonpage to $resultmax</b></td></tr>";

//
//your code for the page here
//


// Previos and next link generator
print("<tr><td align=\"center\" colspan=\"4\">");
$pagestoshow = $num_links2 - $number_of_ads_per_page;
if ( $offset < $pagestoshow ): // MULTIPAGE - if present offset is less than the number of the returned rows then do multipage
$displayNextButton = "true";
$offset = ($offset + $number_of_ads_per_page); // here the offset is incremented to point to the next set of results desired
include("nextpage.php");
else:
if ($pagestoshow == 0)
echo "<b>End of Results</b>";
endif;
print("</td></tr>");
?>

the nextpage.php

<form name="Nextpage" method="post" action="<? $PHP_SELF ?>">
<?
// Previos and next link generator

if ( $offset > 15 ){
echo"<input class=\"box\" type=\"button\" name=\"goBack\" value=\"$previous\" onclick=\"history.back(1)\">";
}
if ( $displayNextButton == "true" ):
?><input class="box" type="submit" name="submit" value="<? echo $next ?>">
<?

endif;

// END of Previos and next link generator
?>

<input type="hidden" name="offset" value="<?php echo $offset;?>">
<input type="hidden" name="num_links2" value="<?php echo $num_links2;?>">
</form>

Paul
01-01-2002, 07:26 PM
Im not sure if that code will work (I might be wrong). Isn't that code splitting the rows of a table into pages? If this is so it will not work as the pics are not in rows but are simply a number in a gallery that tells the script how many times to loop the <img> tag. If I am wrong please let me know as I know a lot less then you on this subject.
Thank You,
Paul

scoutt
01-01-2002, 09:58 PM
well if the pics are numbered in a gallery that tells the script how many times to loop the <img> tag then why have a next and previous links? just curious. you're rigth, that might not work for you..

you can always limit the number of pics to be shown. that way you wouldn't need a next page.

Paul
01-01-2002, 10:18 PM
Oops why didn't I think of that. I could start the loop at a certain number per page. I guess you learn something new everyday.
Thanks,
Paul