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.

PHP Forum


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



Freelance Jobs

Reply
Problem with $Get function
Old 09-04-2012, 11:31 AM Problem with $Get function
Novice Talker

Posts: 9
Trades: 0
Hi
I am fairly new to php, I have a table that has insect names, id, scientific name and descriptions. I am trying to present the table with insect Id name and scientific name. The insect description is too long to fit into the table I therefore want to create a link to a different page which will give the insect description then link back to the home page. I have been trying to find some info on using the get function to retrieve the data but no luck!
this what my code looks like:

PHP Code:
/*create a new mysql query to select insects from a selected table*/
$insects mysql_query     ("SELECT insect_id, insect_slug, insect_com, insect_science, insect_des
                         FROM insects
                         ORDER BY insect_com"
);
             
    echo 
"<table border ='1'";
    echo 
"<h>insects</h>";
    echo 
"<tr><th>insect_slug</th><th>insect_com</th><th>insect_science</th></tr>";
      
/* create a while loop to get the rows of the table */
    
while($row mysql_fetch_array$insects )) {
        
$strInsect $row ['insect_com'];
        
//create a link to the insect description page
     
$strLink =    "<a href='insects-details.php?insect_des = "$row['insect_com']. "'>".$strInsect."</a>";
        
    
// Print out the contents of each row into a table
    
echo "<tr><td>"
    echo 
$row['insect_slug'];
    echo 
"</td><td>";
    echo 
$strLink;
    echo 
"</td><td>"
    echo 
$row['insect_science'];
     echo 
"</td></tr>"
    
    
//echo "<li>".$strLink."</li>";
    
            
}
    echo 
"</table>";
   
    
?> 
Thanking you in advance

Last edited by Physicsguy; 09-04-2012 at 10:14 PM.. Reason: Added code formatting
Theonlybrains is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-04-2012, 12:51 PM Re: Problem with $Get function
chrishirst's Avatar
Defies a Status

Posts: 43,971
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You may have more success using the correct name.

$_GET['keyname']

http://www.php.net/manual/en/reserved.variables.get.php
http://www.w3schools.com/php/php_get.asp
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-04-2012, 10:15 PM Re: Problem with $Get function
Physicsguy's Avatar
404 - Title not found

Posts: 1,061
Name: Scott Kaye
Location: Ontario
Trades: 0
If you're trying to use a literal $get in your function, you might be reading an old tutorial with register_globals on, which is a bad security practice (actually, removed!).
__________________

Please login or register to view this content. Registration is FREE
Physicsguy is offline
Reply With Quote
View Public Profile Visit Physicsguy's homepage!
 
Old 09-06-2012, 09:24 AM Re: Problem with $Get function
Novice Talker

Posts: 9
Trades: 0
Thanks guys for your help, I do not seem to understand where I am going wrong with this! I have created the link to my description page and that works fine. Now I just can get my head round to creating a query or a function to the retrieve individual insect description! this is what my description page code looks like:
<?php
// Make a connection to the host server
mysql_connect("localhost","xxxxxx","xxxxxxxx") or die(mysql_error);
mysql_select_db("khumbu") or die(mysql_error());
/*create a new mysql query to select insects from a selected table*/
$insects = mysql_query ("SELECT insect_id, insect_slug, insect_com, insect_science,insect_des
FROM insects");
$row = $_Get['insect_id'];
echo "<table border ='1'";
echo "<h1>Insect Description</h1>";
echo "<tr><th>insect_des</th></tr>";
echo "<tr><td>";
echo $row['insect_des'];
echo "</td></tr>";
echo "</table>";
?>
I am getting an error that say undefined variable Get
Please help
Theonlybrains is offline
Reply With Quote
View Public Profile
 
Old 09-06-2012, 11:09 AM Re: Problem with $Get function
King Spam Talker

Posts: 1,092
Name: Paul W
Trades: 0
I think you're getting confused over the global _GET - this is an array of the names/values passed in as a get string. They can come from a form submission with method get or can be explicitly added to a link.

This doesn't appear to be what you need here - you just want to retrieve the results of a query and display a row at a time? I'd suggest you read through the chapter on the PHP site http://uk.php.net/manual/en/book.mysqli.php and look at some of the code examples.
__________________
Great music:
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Old 09-06-2012, 06:22 PM Re: Problem with $Get function
chrishirst's Avatar
Defies a Status

Posts: 43,971
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
PHP is case sensitive $_Get is NOT the same as $_GET
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-07-2012, 09:05 AM Re: Problem with $Get function
Physicsguy's Avatar
404 - Title not found

Posts: 1,061
Name: Scott Kaye
Location: Ontario
Trades: 0
As well, $_GET won't do anything for MySQL(i) calls, either. In your latest example, unless you have a ?insect_id URL parameter, your script won't do anything where you call $_Get (and as chrishirst pointed out, it needs to be $_GET).

Here's an example:

If I make a link on my website that looks like this:

Code:
http://example.com/specialpage.php?param1=value1&param2=value2
You can access 'param1' and 'param2' through the $_GET superglobal:

PHP Code:
echo $_GET['param1']; //This would say 'value1'
echo $_GET['param2']; //This would say 'value2' 
Also, in your example, I see you're trying to use the $row variable. It looks like you're trying to do something like this (discouraged, use MySQLi, but this is really simple to learn). This is the proper, new way to do it, except the example code looks a little more daunting at first because there are more sub-examples within them.
__________________

Please login or register to view this content. Registration is FREE
Physicsguy is offline
Reply With Quote
View Public Profile Visit Physicsguy's homepage!
 
Reply     « Reply to Problem with $Get function
 

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.54165 seconds with 11 queries