Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Display data from MYSQL Database:
Old 07-11-2008, 01:10 PM Display data from MYSQL Database:
rolda hayes's Avatar
Wannabe Adventurer...

Posts: 960
Name: Darren
Location: England
Trades: 0
I know this probably has been asked before but I'm trying to achieve something specific that I cant seem to find anywhere....

Here goes...

I need an upload form where someone can enter a famous quote.
on that form, they can select from a drop down or radio button which page the quote should appear on and then press submit.

The quote is then displayed on the correct page.

For example, a quote is entered from a movie, the user selects "movie" from the list, and then the quote appears on movie.php

I have successfuly made the data appear on a page but am having problems getting the "select page" part of it to work.

My database is set up with

CREATE TABLE `quotes` (
`1` VARCHAR( 50 ) NOT NULL ,
`quote` VARCHAR( 300 ) NOT NULL ,
`source` VARCHAR( 300 ) NOT NULL
)

where "1" was going to be the movie page??

Really need some help with this!
__________________
I Just a test to see what happens...
Please login or register to view this content. Registration is FREE

"Let us be thankful for the fools. But for them the rest of us could not succeed..."
rolda hayes is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-11-2008, 02:12 PM Re: Display data from MYSQL Database:
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Huh?

Code:
Create Table PageType (
   TypeID int identity primary key,
   TypeDesc varChar(max)
)

Create Table Quotes (
   QuoteID int identity primary key,
   PageTypeID int not null foreign key references PageType,
   Quote nVarChar(max),
   Author nVarChar(300)
)
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 07-11-2008, 02:16 PM Re: Display data from MYSQL Database:
rolda hayes's Avatar
Wannabe Adventurer...

Posts: 960
Name: Darren
Location: England
Trades: 0
Ah John,

Knew you'd be around (and confusing me as always!)

Same project as last time - really need the option to choose which page to display the quote on...!

i get this error when using your code

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identity primary key,
TypeDesc varChar(max)
)

Create Table Quotes (
' at line 2
__________________
I Just a test to see what happens...
Please login or register to view this content. Registration is FREE

"Let us be thankful for the fools. But for them the rest of us could not succeed..."

Last edited by rolda hayes; 07-11-2008 at 02:25 PM..
rolda hayes is offline
Reply With Quote
View Public Profile
 
Old 07-11-2008, 04:08 PM Re: Display data from MYSQL Database:
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Ah, well, you'll need to change it a bit to suit your taste. varChar(max) and nVarChar(max) are SQL Server specific data types. They're like modern versions of the Text and nText (CLOB) types.

Just replace (max) with a size appropriate to what you need.

Numbers for column names are a bad idea in general, and confused the heck out of me - I think I understand now, tho.

After you size your columns in the code I wrote out, you might do something like

Insert PageType ( TypeDesc ) Values ( 'Sports' )
Insert PageType ( TypeDesc ) Values ( 'History' )
Insert PageType ( TypeDesc ) Values ( 'Stupid Database Garbage' )

Et cetera. The database will generate TypeID values for each of them. If you do what I just typed, above, in that order, Sports will have a TypeID of 1. So you'd follow it up with

Insert Quotes ( PageTypeID, Quote, Author ) Values ( 1, 'Deja vu all over again', 'Yogi Berra' )

I think we've gone over most of the advantages of this approach. Mainly, it makes your application drastically faster as you add more and more data. But also if you add 500,000 sports quotes, then you want to change the label from "Sports" to "Sport Related Quotes" you would change 1 value in the PageType table, and it would instantly be reflected everywhere in your system - because that's the only place it's stored.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 07-11-2008, 04:34 PM Re: Display data from MYSQL Database:
rolda hayes's Avatar
Wannabe Adventurer...

Posts: 960
Name: Darren
Location: England
Trades: 0
are you sure that is not MS-SQL code?

I'm Soooooo lost!

i downloaded NuSphere and used a wizzard to create the database and form - It works well in the preview window, and inserts to the database but dosnt show the form when I upload it to the web!!!
__________________
I Just a test to see what happens...
Please login or register to view this content. Registration is FREE

"Let us be thankful for the fools. But for them the rest of us could not succeed..."
rolda hayes is offline
Reply With Quote
View Public Profile
 
Old 07-11-2008, 04:50 PM Re: Display data from MYSQL Database:
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
I don't know how NuSphere works, or really anything about it.

Which part are you suggesting is Microsoft specific SQL? You may need to spell out INSERT INTO rather than just INSERT, but MySQL supports joins.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 07-11-2008, 06:27 PM Re: Display data from MYSQL Database:
rolda hayes's Avatar
Wannabe Adventurer...

Posts: 960
Name: Darren
Location: England
Trades: 0
SOLVED IT!!!!

ok, for future referance if anyone ever comes accross this thread....

table was created like this
Code:
CREATE TABLE IF NOT EXISTS `quotes` (
  `pageid` varchar(50) NOT NULL,
  `quote` varchar(300) NOT NULL,
  `author` varchar(300) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
submit form:
Code:
<form id="form1" method="post" action="upload.php">
				  <table width="100%" border="0" cellspacing="3" cellpadding="3">
                    <tr>
                      <td width="33%">&nbsp;</td>
                      <td width="67%"><span class="style7">Welcome...</span></td>
                    </tr>
                    <tr>
                      <td><div align="right">Page to Upload to:</div></td>
                      <td><label>
                        <input type="radio" name="pageid" id="pageid" value="1" />
                      </label>
                      General<br />
                      <input type="radio" name="pageid" id="pageid" value="2" />
                      History<br />
                      <input type="radio" name="pageid" id="pageid" value="3" /> 
                      Movies<br />
                      <input type="radio" name="pageid" id="pageid" value="4" />
                      Sport<br />
                      <input type="radio" name="pageid" id="pageid" value="5" /> 
                      TV</td>
                    </tr>
                    <tr>
                      <td><div align="right">Great One Liner:</div></td>
                      <td><label>
                        <input name="quote" type="text" id="quote" size="70" />
                      </label></td>
                    </tr>
                    <tr>
                      <td><div align="right">Author:</div></td>
                      <td><input name="author" type="text" id="author" size="70" /></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td><label>
                        <input type="submit" name="button" id="button" value="Submit" />
                      </label></td>
                    </tr>
                  </table>
              </form>
upload.php:
Code:
<?php

@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$pageid = addslashes($_POST['pageid']);
@$quote = addslashes($_POST['quote']);
@$author = addslashes($_POST['author']);

// Validation
if (strlen($pageid) == 0 )
{
header("Location: error.html");
exit;
}

if (strlen($quote) == 0 )
{
header("Location: error.html");
exit;
}

//saving record to MySQL database


@$pfw_strQuery = "INSERT INTO `quotes`(`pageid`,`quote`,`author`)VALUES (\"$pageid\",\"$quote\",\"$author\")" ;
@$pfw_host = "localhost";
@$pfw_user = "*******";
@$pfw_pw = "*******";
@$pfw_db = "*******";
$pfw_link = mysql_connect($pfw_host, $pfw_user, $pfw_pw);
if (!$pfw_link) {
 die('Could not connect: ' . mysql_error());
}
$pfw_db_selected = mysql_select_db($pfw_db, $pfw_link);
if (!$pfw_db_selected) {
die ('Can not use $pfw_db : ' . mysql_error());
}

//insert new record
$pfw_result = mysql_query($pfw_strQuery);
if (!$pfw_result) {
 die('Invalid query: ' . mysql_error());
}
mysql_close($pfw_link);

header("Location: ok.html");

?>
Then pulled the query with:
Code:
      <?php  
$database="*******";  
mysql_connect ("localhost", "*******", "*******");  
@mysql_select_db($database) or die( "Unable to select database");  
$result = mysql_query( "SELECT quote,author FROM quotes WHERE pageid = 4" )  
or die("SELECT Error: ".mysql_error());  
$num_rows = mysql_num_rows($result);    
print "<table width=700  border=0 cellpadding=5>\n";
$color1 = '#C40000';
$color2 = '#333';
while ($get_info = mysql_fetch_row($result)){  
print "<tr>\n";  
print "\t<td><img src=\"http://www.webmaster-talk.com/images/more.gif\"><font face=arial size=3 color=$color1/>{$get_info[0]}</font><br />";
print  "<font face=arial size=2 color=$color2/>{$get_info[1]}</font></td>\n";  
print "</tr>\n";  
}  
print "</table>\n";  
?>
Cheers for the help John, much appreciated!
The site will be in my sig when finished!
(Again, as like earlier, I can't give you Tp because you have too much today!)
__________________
I Just a test to see what happens...
Please login or register to view this content. Registration is FREE

"Let us be thankful for the fools. But for them the rest of us could not succeed..."

Last edited by rolda hayes; 07-11-2008 at 06:31 PM..
rolda hayes is offline
Reply With Quote
View Public Profile
 
Old 07-11-2008, 08:20 PM Re: Display data from MYSQL Database:
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Excellent that it works!
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-29-2009, 04:08 AM Re: Display data from MYSQL Database:
Junior Talker

Posts: 3
Name: sheela
Trades: 0
Displaying data from a table is a very common requirement and we can do this in various ways depending on the way it is required. We will start with a simple one to just display the records and then we will move to advance one like breaking the returned records to number of pages. We will start with simple displaying the records of this table.
================================
radio controlled toys
family crests
mary2000 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Display data from MYSQL Database:
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28595 seconds with 12 queries