Web Hosting Deals Holiday Logo Design Webcam Chat Website Header Templates Register domain Search Engine Optimisation Web Hosting
Go Back   Talk Mania Forum > Tutorials > PHP / Perl / Java / JavaScript / CGI Tutorials

PHP / Perl / Java / JavaScript / CGI Tutorials PHP / Perl / Java / JavaScript / CGI Tutorials Please do not use this Forum to advertise your site or to link to tutorials.

 Image
Buy Sell Downloads

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-28-2007, 01:53 AM
Turbocharged_06's Avatar
VIP Member
 
Join Date: Mar 2007
Posts: 151
Turbocharged_06 is on a distinguished road
help

im trying to learn php and was trying to display some info from my mysql tutorials table
PHP Code:
<?php
$mysqlhost 
"localhost";
$mysqluser "user";
$mysqlpass "pass";
$mysqltable "table";

mysql_connect$mysqlhost $mysqluser ,$mysqlpass ) or die ("Could not Connect");
mysql_select_db $mysqltable ) or die ("could not select db $mysqltable")
$sql = (" SELECT * FROM tutorials WHERE 1=1; ");
$result mysql_query($sql);
echo 
$result;
?>
i got the error
HTML Code:
 parse error: syntax error, unexpected T_VARIABLE in /home/outlbnet/domains/outlaw-web.net/public_html/teest2.php on line 9

__________________
OUTLAW-WEB.NET
Reply With Quote
  #2 (permalink)  
Old 05-28-2007, 03:05 AM
Junior Member
 
Join Date: Jan 2007
Posts: 29
RonK is on a distinguished road
Quote:
Originally Posted by Turbocharged_06 View Post
im trying to learn php and was trying to display some info from my mysql tutorials table
PHP Code:
<?php
$mysqlhost 
"localhost";
$mysqluser "user";
$mysqlpass "pass";
$mysqltable "table";

mysql_connect$mysqlhost $mysqluser ,$mysqlpass ) or die ("Could not Connect");
mysql_select_db $mysqltable ) or die ("could not select db $mysqltable")
$sql = (" SELECT * FROM tutorials WHERE 1=1; ");
$result mysql_query($sql);
echo 
$result;
?>
i got the error
HTML Code:
 parse error: syntax error, unexpected T_VARIABLE in /home/outlbnet/domains/outlaw-web.net/public_html/teest2.php on line 9
i think this should be right
Code:
<?php
$mysqlhost = "localhost";
$mysqluser = "user";
$mysqlpass = "pass";
$mysqltable = "table";

mysql_connect( $mysqlhost , $mysqluser ,$mysqlpass ) or die ("Could not Connect");
mysql_select_db ( $mysqltable ) or die ("could not select db $mysqltable");
$sql = (" SELECT * FROM tutorials WHERE 1=1; ");
$result = mysql_query($sql);
echo $result;
?>
u just forgot a ; sign
Reply With Quote
  #3 (permalink)  
Old 05-28-2007, 08:33 PM
Senior Member
 
Join Date: May 2007
Posts: 181
Blog Entries: 1
skyfe is on a distinguished road
Quote:
Originally Posted by Turbocharged_06 View Post
im trying to learn php and was trying to display some info from my mysql tutorials table
PHP Code:
<?php
$mysqlhost 
"localhost";
$mysqluser "user";
$mysqlpass "pass";
$mysqltable "table";

mysql_connect$mysqlhost $mysqluser ,$mysqlpass ) or die ("Could not Connect");
mysql_select_db $mysqltable ) or die ("could not select db $mysqltable")
$sql = (" SELECT * FROM tutorials WHERE 1=1; ");
$result mysql_query($sql);
echo 
$result;
?>
i got the error
HTML Code:
 parse error: syntax error, unexpected T_VARIABLE in /home/outlbnet/domains/outlaw-web.net/public_html/teest2.php on line 9
What you want to show from the database? First of all, this will only output(if it would work) 1 or 0... This will output the query RESULT with the query #id... For getting all rows it selected with the query, and set it into a var, you can use mysql_fetch_assoc($var_with_query). And second: You call into the mysql_select_db a TABLE and also one which have not been set into the var yet, caus the variable is defined LATER than it's called... So this should it be:

Quote:
<?php
mysql_connect("localhost", "user", "password");
mysql_select_db("database_name");
$result = mysql_query(" SELECT * FROM tutorials WHERE 1=1; ");
while($row = mysql_fetch_assoc($result)) {
echo $row['field'];
}
?>
where 'field' is the field you want to show, take for example: Inside the table 'tutorials' you have the follow fields:
name author text
and there's 1 row found with the query which have this values in the fields in the table tutorials:
name: Test tutorial
author: Noone
text: test
and you want to show the value of the field 'name' (in this case that's "Test Tutorial" as you can see above) then you can do that like this:

Quote:
<?php
mysql_connect("localhost", "user", "password");
mysql_select_db("database_name");
$result = mysql_query(" SELECT * FROM tutorials WHERE 1=1; ");
while($row = mysql_fetch_assoc($result)) {
echo $row['name'];
}
?>
I hope you understand it some better now Good luck!
Reply With Quote
  #4 (permalink)  
Old 06-07-2007, 09:28 PM
Junior Member
 
Join Date: Jun 2007
Posts: 23
Evan is on a distinguished road
Quote:
Originally Posted by RonK View Post
i think this should be right
Code:
<?php
$mysqlhost = "localhost";
$mysqluser = "user";
$mysqlpass = "pass";
$mysqltable = "table";

mysql_connect( $mysqlhost , $mysqluser ,$mysqlpass ) or die ("Could not Connect");
mysql_select_db ( $mysqltable ) or die ("could not select db $mysqltable");
$sql = (" SELECT * FROM tutorials WHERE 1=1; ");
$result = mysql_query($sql);
echo $result;
?>
u just forgot a ; sign
Haha, good spoting took me a few minz to find that, surprised he didnt see it himself :P
Reply With Quote
  #5 (permalink)  
Old 06-10-2007, 11:47 AM
Member
 
Join Date: Sep 2006
Location: Cyber Space, Uk.
Posts: 91
Nick is on a distinguished road
Send a message via AIM to Nick Send a message via MSN to Nick Send a message via Yahoo to Nick Send a message via Skype™ to Nick
PHP Code:
<?php
// Set Variables
$mysqlhost "localhost";
$mysqluser "user";
$mysqlpass "pass";
$mysqldb "db";

// Connect to the server
mysql_connect($mysqlhost$mysqluser$mysqlpass) or die ("Could not Connect");

// Pick the database
mysql_select_db($mysqldb) or die ("Could not select $mysqldb");

// Query for all the tutorials.
$tutorials mysql_query("SELECT * FROM tutorials");

while (
$tut mysql_fetch_array($tutorials))
{
    
print_r($tut);
}
?>
Neat code is good code.

What that will do is query into the tutorial table for all the tutorials then for each tutorial it finds it will output an array of information in the format;
field => data

Depending on what columns your table has, you could use this;
PHP Code:
<?php
// Set Variables
$mysqlhost "localhost";
$mysqluser "user";
$mysqlpass "pass";
$mysqldb "db";

// Connect to the server
mysql_connect($mysqlhost$mysqluser$mysqlpass) or die ('Could not Connect');

// Pick the database
mysql_select_db($mysqldb) or die ('Could not select ' $mysqldb);

// Query for all the tutorials.
$tutorials mysql_query("SELECT * FROM tutorials");

$code '<table border="1" width="50%" align="center" cellpadding="6" cellspacing="1">';
while (
$tut mysql_fetch_array($tutorials))
{
    
$code .= '    <tr>';
    
$code .= '        <td><strong>Title: </strong>' $tut['title'] . '</td>';
    
$code .= '        <td><strong>Posted By: </strong>' $tut['user'] . '</td>';
    
$code .= '        <td><strong>Date: </strong>' $tut['date'] . '</td>';
    
$code .= '    </tr>';
}

$code .= '</table>';
echo 
$code;
?>
__________________
Nick - Coder/Designer
Reply With Quote
  #6 (permalink)  
Old 06-10-2007, 12:11 PM
Senior Member
 
Join Date: May 2007
Posts: 181
Blog Entries: 1
skyfe is on a distinguished road
yeah, print_r(array) shows the content of an array, in this case $tut contains all rows that have been found, good script
array(field => value)
will output for each field that have been found in a row with the query I guess?
Reply With Quote
  #7 (permalink)  
Old 06-10-2007, 12:15 PM
Member
 
Join Date: Sep 2006
Location: Cyber Space, Uk.
Posts: 91
Nick is on a distinguished road
Send a message via AIM to Nick Send a message via MSN to Nick Send a message via Yahoo to Nick Send a message via Skype™ to Nick
It will output something like this for each row found;

Code:
Array
(
    [field1] => value1
    [field2] => value2
    [field3] => value3
    [field4] => value4
    [field5] => value5
)
You can view a demo here; http://www.vbulletin-skins.com/arr.php
__________________
Nick - Coder/Designer
Reply With Quote
  #8 (permalink)  
Old 06-10-2007, 12:15 PM
Senior Member
 
Join Date: May 2007
Posts: 181
Blog Entries: 1
skyfe is on a distinguished road
yeah, for each row

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +2. The time now is 01:35 AM.


Fake ID

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC8
Forums Copyright © Talk-Mania.com