473,396 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Selecting rows from db table

In a project mentioned in another thread, I'm trying to get some
dynamic data to work. In this discography, you can click on an
album name, and the title of the album and its tracks will appear
on the left. I have the beginnings worked out, like so:

***

<h3><?php echo $row_rsindiv['Album']; ?></h3>
<ol>
<?php do { ?>
<li><?php echo $row_rsindiv['Song']; ?> (<?php echo $row_rsindiv
['Time']; ?>)</li>
<?php } while ($row_rsindiv = mysql_fetch_assoc($rsindiv)); ?>
</ol>

***

A sample of the database:

***

Electronic Meditation 3 Cold Smoke 10:48
Electronic Meditation 4 Ashes to Ashes 3:58
Electronic Meditation 5 Resurrection 3:21
Alpha Centauri 6 Sunrise in the Third System 4:20
Alpha Centauri 7 Fly and Collision of Comas Sola 13:23
Alpha Centauri 8 Alpha Centauri 22:04
Zeit 9 Birth of Liquid Plejades 19:52
Zeit 10 Nebulous Dawn 17:47

***

I want to tell PHP to write the album name and list the tracks in
an <li></li> based on whatever album title is clicked in the main
table.

The main table looks like:

***

<?php do { ?>
<?php
$class = ($class == 'odd') ? 'even' : 'odd';
?>
<tr class="<?php echo $class ?>">
<td><?php echo $row_rstdream['Album']; ?></td>
<td><?php echo $row_rstdream['Year']; ?></td>
<td><?php echo $row_rstdream['Era']; ?></td>
<td><?php echo $row_rstdream['Type']; ?></td>
</tr>
<?php } while ($row_rstdream = mysql_fetch_assoc($rstdream)); ?>

***

I thought maybe of changing the first <td></td> to:

<td><a href="#" onclick="<?php $album = $row_rstdream['Album'] ?>">
<?php echo $row_rstdream['Album']; ?></td>

But that's as far as I can get with my limited knowledge. Does
anyone have any ideas on how to display only the rows in the second
database that correspond to the name of the album clicked on? Sorry
the examples are so long, and I hope this makes sense.

TIA
Ian
--
http://www.bookstacks.org/
Jul 17 '05 #1
11 1937
Well, this new thread appears to have been rather pointless, as
I've figured out the problem.

From the top of the page:

$album=$_GET['album'];

$query_rsindiv = "SELECT * FROM indiv_album WHERE
Album='$album' ORDER BY Number ASC";

This is grabbing the value of the $album variable, set when you
click on an album name in the dynamic table, like so:

<td><a href="<?php print $_SERVER['PHP_SELF']."?album=".
$row_rstdream['Album']; ?>"><?php echo $row_rstdream['Album']; ?>
</a></td>

The dynamic data comes from:

<?php if ($album) { ?>
<h3><?php echo $row_rsindiv['Album']; ?></h3>
<ol>
<?php do { ?>
<li><?php echo $row_rsindiv['Song']; ?> (<?php echo
$row_rsindiv['Time']; ?>)</li>
<?php } while ($row_rsindiv = mysql_fetch_assoc($rsindiv)); ?>
</ol>
<?php } ?>

and it tests the $album variable to make sure it's got a value,
so that nothing shows up when the page is first loaded.

If that's helpful to anyone, I'm glad. Either way, it would be
rude not to post the answer, even if I asked the question. :-)

Ian
--
http://www.bookstacks.org/
Jul 17 '05 #2
I noticed that Message-ID: <Xn**************************@130.133.1.4>
from Ian Rastall contained the following:
<td><a href="#" onclick="<?php $album = $row_rstdream['Album'] ?>">
<?php echo $row_rstdream['Album']; ?></td>

But that's as far as I can get with my limited knowledge. Does
anyone have any ideas on how to display only the rows in the second
database that correspond to the name of the album clicked on?


You really need to get your head around the fact that once the results
appear on your screen, all PHP scripts are finished. Onclick is just
for client side events. You'll only get new results if you pass
different variables to the script, and check for them before you do the
query.

In this case you need to pass the variable into the script via a query
string in the URL, like I showed you before.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3
On 2005-01-31, Ian Rastall <id*******@gmail.com> wrote:
Well, this new thread appears to have been rather pointless, as
I've figured out the problem.

From the top of the page:

$album=$_GET['album'];

$query_rsindiv = "SELECT * FROM indiv_album WHERE
Album='$album' ORDER BY Number ASC";


One should never trust input from the evil angry user.

As you are using MySQL, read http://www.php.net/mysql_real_escape_string
and change your code for use in the real world.

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #4
In comp.lang.php Geoff Berrow wrote:
In this case you need to pass the variable into the script via
a query string in the URL, like I showed you before.


Hey Geoff. That's what I ended up doing (taking out the onclick and
passing the variable in the URL). What really bugs me is that when
I had this page done before, in JavaScript, I was able to add text
beside the sortable table without reloading the page. I believe I
was messing with document.innerHtml, which I guess means I was
messing with the DOM. Before I had discovered that trick, I was
creating text input fields with no borders and writing to those.
Not that JavaScript is relevant to this group, but I had just
managed to get to that point, where I could alter the page without
having to ask for it again, and can't seem to reach the same point
in PHP. I guess it doesn't make sense that the document could re-
query the database without re-loading the page.

Ian
--
http://www.bookstacks.org/
Jul 17 '05 #5
In comp.lang.php Tim Van Wassenhove wrote:
One should never trust input from the evil angry user.


I should really provide a URL, so you can see what I'm doing, but I
haven't yet figured out how to get the mySQL database off my own
computer and on to my hosting company's server. (I've been doing
this for about five days or so.) :-) My point is, there's nothing
for the user to enter. There's just links to click on. But I'll
read the document you provided.

Ian
--
http://www.bookstacks.org/
Jul 17 '05 #6
I noticed that Message-ID: <Xn***************************@130.133.1.4>
from Ian Rastall contained the following:
My point is, there's nothing
for the user to enter. There's just links to click on.


Right click the link.
Click copy shortcut.
Paste into browser address bar.
Edit maliciously.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #7
In comp.lang.php Geoff Berrow wrote:
Right click the link.
Click copy shortcut.
Paste into browser address bar.
Edit maliciously.


Okay. I'll have to work on this.

Ian
--
http://www.bookstacks.org/
Jul 17 '05 #8
On 31 Jan 2005 07:58:10 GMT, Ian Rastall <id*******@gmail.com>
reverently intoned upon the aether:
In comp.lang.php Tim Van Wassenhove wrote:
One should never trust input from the evil angry user.


I should really provide a URL, so you can see what I'm doing, but I
haven't yet figured out how to get the mySQL database off my own
computer and on to my hosting company's server. (I've been doing
this for about five days or so.) :-) My point is, there's nothing
for the user to enter. There's just links to click on. But I'll
read the document you provided.

Ian


Hi Ian,

This is the same general topic as "SQL Injection" which I mentioned
earlier. Essentially it amounts to:

"Users are evil!"

And I admit to being one of them. Users could care less how your
coded it, they expect it to work. I am impatient, I hate waiting, and
did I mention I hate software that makes me do 5 things to do 1 thing?
;o)

And more seriously (the above is dead serious), even when a user is
not malicious, they still tend to f#$% things up and break stuff (see
impatience above). Actually, in my experience, users often cause more
grief with software than malicious hackers as they tend to blithely do
what they want the software to do rather than what the software wants
them to do.

And in truth, 90% of computer security (remember, you are on the web
with a website visible to the whole world [or at least most of the
industrialized world and climbers with laptops, solar power, and
satellite uplinks on the middle slopes of Mt. Everest {the sleazy
white guy name, not the real name it had for the previous ten to
fifteen thousand years as I fear Chomolungma is spelled wrong}] ;o).

Social commentary aside, the issue here is input validation. A
non-malicious user will cause an error far more often than a malicious
hacker. Why? Sometimes it will be a transmission error. Sometimes
they do things in the wrong order (use the back button at the wrong
moment?). The cause matters little, the random chaos of a real user
often breaks things far more often than the organize malice of
hacker/cracker.

In short, taking a website dynamic opens a whole can of worms that
does not exist in a static website or some software written in C.
Remember, most mistakes written in C execute and break the users
computer, not your customer's website.

enjoy,

Sean
"In the End, we will remember not the words of our enemies,
but the silence of our friends."

- Martin Luther King Jr. (1929-1968)

Photo Archive @ http://www.tearnet.com/Sean
Last Updated 29 Sept. 2004
Jul 17 '05 #9
.oO(Ian Rastall)
In comp.lang.php Geoff Berrow wrote:
Right click the link.
Click copy shortcut.
Paste into browser address bar.
Edit maliciously.


Okay. I'll have to work on this.


Just remember this: Everything(!) coming in from the client side can be
manipulated, even the content of hidden or read-only form fields. You
don't really have to think about how or where, but simply accept that
it's possible and then take care of that in your scripts. If you want to
process user-submitted data, validate it first. Always.

The problem is not the average visitor who simply uses your site, but
the more experienced evil guy who explicitly looks for security holes,
as seen recently in phpBB.

Micha
Jul 17 '05 #10
On 2005-01-31, Ian Rastall <id*******@gmail.com> wrote:
In comp.lang.php Tim Van Wassenhove wrote:
One should never trust input from the evil angry user.


I should really provide a URL, so you can see what I'm doing, but I
haven't yet figured out how to get the mySQL database off my own
computer and on to my hosting company's server. (I've been doing
this for about five days or so.) :-) My point is, there's nothing
for the user to enter. There's just links to click on. But I'll
read the document you provided.


Your statement has already been debunked by others, so i won't do that
again...

But let me say this: If you consider security as a priority from the
start, it's usually not that difficult to come up with a relative secure
application. But if you start adding it afterwards, you'll probably
experience problems (just look at the problems ms has with windows :p)

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #11
In comp.lang.php Tim Van Wassenhove wrote:
If you consider security as a priority from the
start, it's usually not that difficult to come up with a
relative secure application.


Believe me, I'm listening, it's just that this is a bit over my
head. Essentially, I got tired of reading about PHP and mySQL and
just dove right in, so it will take some time to learn good
security practices. I'll work on mysql_real_escape_string(), or,
rather, will work on figuring out how to use it. :-)

Thanks for everyone's comments.

Ian
--
http://www.bookstacks.org/
Jul 17 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Axial | last post by:
Question: How to select columns from Excel-generated XML when some cells are empty. I've found examples where rows are to be selected, but I can't seem to extrapolate from that to selecting...
2
by: Robert | last post by:
Hi All, I'm trying to solve this for a few days now and I just can't figure it out... I have three tables set up, I'll simplify them for this question: Table 1: HOTELS Columns: HOTEL_ID,...
4
by: remote89 | last post by:
Hi experts, I have been trying to limit the table rows in the following situation, any suggestions will be appreciated. we have table called tempTb has columns id, c_id, c_name, rating, date...
5
by: jamie | last post by:
Hi, I have a table with 1 million rows that I need to delete. Is there a way to delete them quickly considering I get errors if I try to select them all and then hit delete? What I'm...
6
by: aaj | last post by:
Hi all I use a data adapter to read numerous tables in to a dataset. The dataset holds tables which in turn holds full details of the records i.e. keys, extra colums etc.. In some cases I...
1
by: Jay | last post by:
Hi All, My users are complaining about the page refreshing when they are selecting multiple rows in a datagrid. Has anyone tried to manage this using javascript? I tried smartnavigation but that...
2
by: Mike Kelly | last post by:
Hi. I have a data table where rows are grouped according to a certain criteria and I want to be able to display all the rows that belong to the same group together on the screen. In addition, I...
48
by: phillip.s.powell | last post by:
MySQL 3.23.58 - 4.0.17 (yep, several database server instances, don't ask) I have database Spring with table Students I have database Summer with table Students I am tasked to produce a...
1
by: Andy | last post by:
Hi Gang I have a simple single table that has many duplicate rows in them. The distinctrows only works on more than one table. Is there a quick and easy way to select only the distict rows...
5
by: Mahesh S | last post by:
Hi I would like to write a SQL select statement that would fetch rows numbered 50 to 100. Let me clarify, if i say "fetch first 10 rows only", it returns the first 10 rows from the resultset....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.