Help
Search
Login
Register
Home
Forum: web design and graphics community
Celestial Star Forum
>
Web Development
>
Coding
>
how to sort by series
Pages: [
1
]
« previous
next »
Print
Author
Topic: how to sort by series (Read 512 times)
Rosie
Angeling
Posts: 6
how to sort by series
«
on:
March 27, 2008, 01:22:04 PM »
I want to sort by pngs by series like this
http://celestial-star.net/layouts/series/
how can I do this? My php knowledge is limited so I really need lots of help with this. The code I currently have displaying my pngs is as follows;
Code:
<?php
$hostname
=
""
;
$user
=
""
;
$pass
=
""
;
$dbname
=
""
;
$connection
=
mysql_connect
(
"$hostname"
,
"$user"
,
"$pass"
);
$db
=
mysql_select_db
(
$dbname
,
$connection
) or die (
"Cannot select db"
);
$q
=
"SELECT * from png order by id desc "
;
$result
=
mysql_query
(
$q
) or die
(
"Could not execute query : $q."
.
mysql_error
());
$screen
=
$_GET
[
'screen'
];
$PHP_SELF
=
$_SERVER
[
'PHP_SELF'
];
$rows_per_page
=
4
;
$total_records
=
mysql_num_rows
(
$result
);
$pages
=
ceil
(
$total_records
/
$rows_per_page
);
if (!isset(
$screen
))
$screen
=
0
;
$start
=
$screen
*
$rows_per_page
;
$q
.=
"LIMIT $start, $rows_per_page"
;
$result
=
mysql_query
(
$q
) or die
(
"Could not execute query : $q."
.
mysql_error
());
// Continue usual Code, display data
$c
=
0
;
echo
'
<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" width=\"90%\"><tr><td> </td></tr> <tr>
'
;
while (
$row
=
mysql_fetch_array
(
$result
))
{
extract
(
$row
);
if (
$c
==
0
)
{
echo
"
<td class=\"outline\">
<center><img src=\"$image\" class=\"button\" width=\"125\" height=\"100\" alt=\"$series\" title=\"$series\"> <br/>
<a target=\"_new\" href=\"pngdownload.php?id=$id\"><strong>Download</strong></a>: $downloaded </center>
</td>
"
;
}
else
{
echo
"
<td class=\"outline\">
<center><img src=\"$image\" class=\"button\" width=\"125\" height=\"100\" alt=\"$series\" title=\"$series\"> <br/>
<a target=\"_new\" href=\"pngdownload.php?id=$id\"><strong>Download</strong></a>: $downloaded </center>
</td><tr></tr>
"
;
}
$c
++;
$c
=
$c
%
2
;
}
echo
'</table><br /></center>'
;
if (
$screen
>
0
) {
$j
=
$screen
-
1
;
$url
=
"$PHP_SELF?screen=$j"
;
echo
"<a href=\"$url\">Prev</a> | "
;
}
// page numbering links now
for (
$c
=
0
;
$c
<
$pages
;
$c
++) {
$url
=
"$PHP_SELF?screen="
.
$c
;
$j
=
$c
+
1
;
echo
" <a href=\"$url\">$j</a> | "
;
}
if (
$screen
<
$pages
-
1
) {
$j
=
$screen
+
1
;
$url
=
"$PHP_SELF?screen=$j"
;
echo
"<a href=\"$url\">Next</a>"
;
}
?>
Logged
Vangs
Administrator
Valkyrie Randgris
Posts: 525
Re: how to sort by series
«
Reply #1 on:
March 27, 2008, 02:04:20 PM »
Have you actually tried to do this yourself or are you just asking us to do it? I'll certainly help you, but I'm not going to just spoon feed you solutions to what you need to do, you'll never learn that way.
Try to work it out yourself first, and if you already have, show me what you have. I'll show you what you're doing wrong if you have already attempted, then that way you'll actually learn and improve for it. But otherwise, if you just want the script handed to you, well that's what professional paid scripting services are for, like the service I, myself provide.
Logged
Rosie870
Angeling
Posts: 8
Re: how to sort by series
«
Reply #2 on:
March 27, 2008, 07:09:33 PM »
No I wasn't asking to be spoon feed here. I wasn't clear in my question, I was basically asking for a tutorial on how to do this. To answer your question, yes I have tried to do this on my own but it doesn't work. Here is the coding I have:
This part below works...
Code:
<?php
$hostname
=
""
;
$user
=
""
;
$pass
=
""
;
$dbname
=
""
;
$connection
=
mysql_connect
(
"$hostname"
,
"$user"
,
"$pass"
);
$db
=
mysql_select_db
(
$dbname
,
$connection
) or die (
"Cannot select db"
);
mysql_select_db
(
"png"
);
$query
=
"SELECT DISTINCT series FROM png order by series asc "
;
$result
=
mysql_query
(
$query
,
$connection
) or die
(
"Could not execute query : $q."
.
mysql_error
());
while (
$row
=
mysql_fetch_array
(
$result
)) {
$series
=
$row
[
"series"
];
$q
=
mysql_query
(
"select * from `png` where `series`='$series'"
);
$numrows
=
mysql_num_rows
(
$q
);
echo
"
<li><a href='series2.php?series=$series'>$series</a> ($numrows renders) </li> "
;
}
?>
But when the series name is clicked nothing shows up. This is the coding I have for the result page:
Code:
<?php
$hostname
=
""
;
$user
=
""
;
$pass
=
""
;
$dbname
=
""
;
$connection
=
mysql_connect
(
"$hostname"
,
"$user"
,
"$pass"
);
$db
=
mysql_select_db
(
$dbname
,
$connection
) or die (
"Cannot select db"
);
mysql_select_db
(
"png"
);
$displayGroup
=
10
;
if (
$_GET
[
'group'
])
$displayGroup
=
$_GET
[
'group'
];
$page
=
0
;
if (
$_GET
[
'screen'
])
$page
=
$_GET
[
'screen'
];
$firstRow
=
$page
*
$displayGroup
;
$lastRow
=
$firstRow
+
$displayGroup
;
$currentRow
=
0
;
$totalRows
=
0
;
$numberDisplayed
=
0
;
$result
=
mysql_query
(
"select * from png where series='$series' order by id desc"
);
if (!
$result
) {
echo
"<p>There is no data available!</p>"
;
return;
}
// Continue usual Code, display data
$c
=
0
;
echo
'
<p align=\"center\">
<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" width=\"90%\"><tr><td> </td></tr> <tr>
'
;
while (
$row
=
mysql_fetch_array
(
$result
))
{
extract
(
$row
);
if (
$c
==
0
)
{
echo
"
<td class=\"outline\">
<div id=\"st\">
<center><img src=\"$image\" class=\"button\" width=\"125\" height=\"100\" alt=\"$id\"></center>
<ul>
<li> <strong>date</strong>: $date </li>
<li> <a target=\"_new\" href=\"pngdownload.php?id=$id\"><strong>Download</strong></a>: $downloaded </li>
</ul>
</div>
</td>
"
;
}
else
{
echo
"
<td class=\"outline\">
<div id=\"st\">
<center><img src=\"$image\" class=\"button\" width=\"125\" height=\"100\" alt=\"$id\"></center>
<ul>
<li> <strong>date</strong>: $date </li>
<li> <a target=\"_new\" href=\"pngdownload.php?id=$id\"><strong>Download</strong></a>: $downloaded </li>
</ul>
</div>
</td><tr></tr>
"
;
}
$c
++;
$c
=
$c
%
2
;
}
echo
'</table><br />'
;
if (
$screen
>
0
) {
$j
=
$screen
-
1
;
$url
=
"$PHP_SELF?screen=$j"
;
echo
"<a href=\"$url\">Prev</a> | "
;
}
// page numbering links now
for (
$c
=
0
;
$c
<
$pages
;
$c
++) {
$url
=
"$PHP_SELF?screen="
.
$c
;
$j
=
$c
+
1
;
echo
" <a href=\"$url\">[$j]</a> | "
;
}
if (
$screen
<
$pages
-
1
) {
$j
=
$screen
+
1
;
$url
=
"$PHP_SELF?screen=$j"
;
echo
"<a href=\"$url\">Next</a>"
;
}
?>
Logged
Vangs
Administrator
Valkyrie Randgris
Posts: 525
Re: how to sort by series
«
Reply #3 on:
March 28, 2008, 03:50:41 AM »
Add this piece of coding into the top of your second file:
Code:
$series = mysql_real_escape_string($_GET['series']);
You aren't getting the value from the URL, so are querying for any series with no name. This fixes that, it also sanitizes the data from malicious user input.
Logged
Rosie
Angeling
Posts: 6
Re: how to sort by series
«
Reply #4 on:
March 28, 2008, 11:05:13 AM »
Wow that was easier than I thought. It worked. Thank you for your help.
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
General
-----------------------------
=> General
=> New Members
=> Announcements
=> Support / Suggestions
-----------------------------
Contests
-----------------------------
=> Archive
===> Contests
===> Blend Challenges
===> SOTW
-----------------------------
Art Boards
-----------------------------
=> Creative mediums
=> Requests & offers
=> Tutorials
===> Celestial Star Tutorials
-----------------------------
Web Development
-----------------------------
=> Coding
=> Web Design
=> Advertisements / Affiliation
-----------------------------
Off-topic
-----------------------------
=> Entertainment
-----------------------------
Español (Spanish Only)
-----------------------------
=> General / Bienvenida
=> Anuncios / Ayuda
=> Código / Desarrollo web
Welcome,
Guest
Members login
Register for free
General
General
New members
Announcements
Support / Suggestions
Art boards
Creative mediums
Requests and offers
Tutorials
Celestial Star tutorials
Web development
Coding
Web design
Advertisements / affiliation
Off-topic
The non-sense
Ententainment
Loading...