Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Subject: using links to pull from mysql

Original Message
Name: BigShow
Date: April 29, 2008 at 08:00:52 Pacific
Subject: using links to pull from mysql
OS: xp
CPU/Ram: pentium
Model/Manufacturer: dell
Comment:
This is definately my toughest program yet. I have been fooling around with this thing for almost 2 weeks and have gotten no where. If it can't be done, I am hoping someone can tell me that so I can move on.

Here it is...I have a page called book that when it loads it is populated with the bookcovers from a database. Each cover obvously represents a book. There are several series in this collection. I need to make it so when someone clicks on a book cover it takes them to a page that shows that cover, some info on it then an excerpt from that book. I created the template for that page nad just figured the best way is to populate the template with whichever book and info the user clicks.

Problem...someone will be clicking an image link, not a submit button so I really cant use a form to extract the info and populate the template. How do I manage to do this? I have been trying to use Javascript onclick() to create a link with an id from the book and open up a page accordingly but I am getting no where. I was going to use Ajax but then that eliminates the back button and that is important to have for this particular section.

Any Ideas?


Report Offensive Message For Removal

Response Number 1
Name: Michael J (by mjdamato)
Date: April 30, 2008 at 19:53:10 Pacific
Subject: using links to pull from mysql
Reply: (edit)
You are making it much harder than it needs to be (hmm, this appears to be a pattern for you - lol). I am assuming you are using PHP on this project as well.

Anyway, on the page that displays the book covers you just need to create standard HTML links of the images pointing to the template page and add a parameter to the URL. You can then access the parameter through the $_GET array, just as you would do with $_POST data (FYI: You know you can set a form's METHOD to either POST or GET, right? Not that we are using a form here, but just for future info)

I will assume that the data for each book is in a database. So, let's say the page that show's an individual books data is "showbook.php". You would create a link that looks something like this: showbook.php?id=5

On that page you would simply get the value for $_GET['id'] (in this case 5) and then do a database query for the book record that has an id of 5.

EDIT: Now that I think of it you *could* use form as well. Just create many mini-forms for each book cover with the image as the submit button. However, that would be ineficient in my opinion.

Michael J


Report Offensive Follow Up For Removal

Response Number 2
Name: BigShow
Date: May 1, 2008 at 10:35:10 Pacific
Subject: using links to pull from mysql
Reply: (edit)
Your right Michael, I need to start giving more thought to it before I post. I have actually started doing what you mentioned just before you answered. Honestly I dont even think that is what I need help with, the part that is over welming me is the script used to make this happen. Let me explain.

Basically there are 7 series of books, each series has X amount of books. I need to first create a page that show all of the book covers, which I will call books.php. I have create two databases, one called book_titles and the other book_info. The book titles has the titles and an ID, the books_info has the titles, series, excerpts and some other tid bits about the book.

Basically on the books page when it opens I want it to pull all the books out of the database and display them across the page in rows of seven, after one row finishes the line automatically breaks and it goes to the next line and continues. This also has to be sectioned off in series so once the series ends it goes to the next line, prints the new series name then goes to the next line and continues showing those book covers. This is why I have 2 tables in the DB for this. I figure I can take all the series names from the forst db, basically write it so it takes all the bookcovers from the first series shows them then goes back and gets the next series name from the table, compares that to the book_info table and prints all those out so on and so forth.

I dont think this is complex but I am overwhelmed trying to make it work, this will involve a few different loops.

Does this seem like something that can be done or should I approach it another way.


Report Offensive Follow Up For Removal

Response Number 3
Name: Michael J (by mjdamato)
Date: May 2, 2008 at 01:14:07 Pacific
Subject: using links to pull from mysql
Reply: (edit)
Yes, it can be done. I don't understand your logic for the two tables. If all the data has a 1-to-1 relationship put all the data into one table. If there is a many-to-one relationship then you need two tables.

Here is some mock code:

<?php


$query = "SELECT id, title, series, cover
FROM books
ORDER BY series, title";

$result = mysql_query($query) or die (mysql_error());


$columns = 7;
$current_series = '';


while ($record = mysql_fetch_assoc($result)) {


//For new series complete last row if not first column
if ($current_series != $record['series']) {
if ($current_column > 1) {
for ($col=$current_column; $col<=$columns; $col++) {
echo "<td> </td>";
}
echo "</tr>";
}


$current_series = $record['series'];
$current_column = 1;
}


//Start new rows for first column
if ($current_column == 1) {
echo "<tr>";
}


//Display the book cover
echo "<td></td>";


$current_column++;


//Close rows for last column
if ($current_column > $columns) {
echo "</tr>";
$current_column = 1;
}


}


//Close the last row (if needed)
if ($current_column > 1) {
for ($col=$current_column; $col<=$columns; $col++) {
echo "<td> </td>";
}
echo "</tr>";
}


?>

Michael J


Report Offensive Follow Up For Removal

Response Number 4
Name: BigShow
Date: May 6, 2008 at 09:32:57 Pacific
Subject: using links to pull from mysql
Reply: (edit)
Hey Michael, I figured out a different way. I created a wrap in css and put in individual cells the size of the covers and made them all float left, i through in the clearfix class adn as the row gets too big it automatically shoots down to the next row. Works great.

Also, Instead of one table I created a table for each series that way each series has ts own div in the code so there doesnt have to be a dozen ifs in my while loop.

Next question, I am running into a syntax error. I know this is right but it wont work. I have a table called 'dark_hunter', in that table i have a cloumn called 'book_title'. When someone clicks the bookcover it brings them to the 'bookdisplay' page where the book title and series is appended to the URL, I GET them and use that in my DB query.

This is my query

$result = mysql_query("SELECT * FROM $bookseriesfordisplay WHERE book_title = `$booktitlefordisplay`")

$bookseriesfordisplay is the series and $booktitlefordisplay is the title. I know these work because I did a little checking and echoed them out so I know the correct info is passing. Here is the error..

Unknown column 'dragonswan' in 'where clause'

dragonswan is the book_title passed over.

Any ideas?


Report Offensive Follow Up For Removal

Response Number 5
Name: Michael J (by mjdamato)
Date: May 6, 2008 at 18:04:27 Pacific
Subject: using links to pull from mysql
Reply: (edit)
I would guess that the values for $bookseriesfordisplay and $booktitlefordisplay are swapped. One bit of advice - never "set" your queries direcrectly in the mysql_query() command. Instead save the query to a variable so you can echo it to the page if somethign gioes wrong for debugging purposes (and also use appropriate debugging code to exit gracefully from an error). Like this:


$query = "SELECT *
FROM $bookseriesfordisplay
WHERE book_title = `$booktitlefordisplay`"

$result = mysql_query($query);

if ($result == false) {
echo "The query:[br /]$query[br /]";
echo "Produced the error:[br /]".mysql_error());

} else {
//Success code goes here
}

Michael J


Report Offensive Follow Up For Removal

Response Number 6
Name: BigShow
Date: May 6, 2008 at 18:27:27 Pacific
Subject: using links to pull from mysql
Reply: (edit)
You know what it was, I needed to put single quotes around the string output at the end not the kicks.

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: using links to pull from mysql

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software



Version Tracker Pro
Keep your software current and secure, effortlessly

Click Here for a Free Scan

Driver Agent
Automatically find the latest drivers for your computer.
Click Here for a Free Scan



The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC