Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-19-2005, 03:24 PM
error_22 error_22 is offline
 
Join Date: Nov 2004
Location: Stockholm, Sweden
Posts: 108
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default get information from database

hi, im trying to learn how this works, but sadly i can't get it working. What am I doing wrong? The databse is called "test" and the only table i have is named "logo". There is one field in the logo table which also is named "logo"

PHP Code:
$server         "localhost";
$db_name     "dbname"
$user         "user";
$pass           "pass";

$logo="SELECT test * FROM logo";

$db_connection 
mysql_connect("$server","$user","$pass"
or die (
"No DB Connection");
$db mysql_select_db("$db_name",$db_connection
or die (
"Couldn't select DB");

echo 
"$logo"
the "logo" field contains the URL to my logo. when running this i get a red cross. Can someone help an newbie?

Thanks in advance
Niklas

The
Reply With Quote
  #2  
Old 10-19-2005, 03:31 PM
peterska2 peterska2 is offline
 
Join Date: Oct 2003
Location: Manchester, UK
Posts: 6,504
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Database stuff isn't my strong point, but I believe that this should work.

PHP Code:
 $server         "localhost";
$db_name     "dbname"
$user         "user";
$pass           "pass";

$logo="SELECT logo * FROM logo";

$db_connection 
mysql_connect("$server","$user","$pass"
or die (
"No DB Connection");
$db mysql_select_db("$db_name",$db_connection
or die (
"Couldn't select DB");

echo 
"$logo"
DISCLAIMER: As stated at the top of this post, database stuff is NOT my strong point. I strongly reccomend that you back up before attempting this. I will NOT be held responsible for any damage caused by this code. USE THIS AT YOUR OWN RISK
Reply With Quote
  #3  
Old 10-19-2005, 03:43 PM
error_22 error_22 is offline
 
Join Date: Nov 2004
Location: Stockholm, Sweden
Posts: 108
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

no it doesnt.... i get a blank page containg this:

SELECT logo * FROM logo

:ermm:
Reply With Quote
  #4  
Old 10-19-2005, 04:21 PM
CommuneZoom CommuneZoom is offline
 
Join Date: Sep 2005
Posts: 29
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

With the above code, you are not running the query, rather, you are simply having the script echo out what is between the " ". You need to add more code to have the query run successfully.

I take it from the above coding you are not integrating this with vBulletin? If not, try the below.

PHP Code:
$server "localhost";
$db_name "dbname"
$user "user";
$pass "pass";

$getlogo mysql_query("SELECT logo FROM logo");
while (
$data mysql_fetch_array($getlogo))
{
echo 
$data[logo]

That does run the query through a loop, though it should provide the desired effect. Alternatively, you may also swicth it to:

PHP Code:
$server "localhost";
$db_name "dbname"
$user "user";
$pass "pass";

$getlogo mysql_query("SELECT * FROM logo");
while (
$data mysql_fetch_array($getlogo))
{
echo 
$data[logo]

With the above, you can call $data[logo] or $data[anythingelse] from the table.


If you were integrating this with vBulletin, you could just as well use the below and cut back on the coding:

PHP Code:
require_once("./global.php");

$getlogo $db->query_read("SELECT * FROM logo");
while (
$data $db->fetch_array($getlogo))
{
echo 
$data[logo]

Reply With Quote
  #5  
Old 10-19-2005, 06:02 PM
error_22 error_22 is offline
 
Join Date: Nov 2004
Location: Stockholm, Sweden
Posts: 108
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you so much for the help!!

Im doing something wrong though, cause it still doesnt work....

Parse error: parse error, unexpected '}', expecting ',' or ';' in /home/wwwocto2/public_html/kabelkontakten/index.php on line 18

line 18 looks like this:

PHP Code:

its the one after echo $data[logo]

any thoughts?


Thanks!
Reply With Quote
  #6  
Old 10-19-2005, 06:46 PM
Wired1's Avatar
Wired1 Wired1 is offline
 
Join Date: Nov 2003
Location: Orlando, FL, USA
Posts: 1,361
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

IIRC this should work:

PHP Code:
<?php

$server 
"localhost"
$db_name "dbname" 
$user "user"
$pass "pass";

$logo="SELECT logo * FROM logo";

// Make a MySQL Connection
mysql_connect($server$user$pass) or die(mysql_error());

mysql_select_db($db_name) or die(mysql_error());


// Retrieve all the data from the "example" table
$result mysql_query($logo) or die(mysql_error()); 


while(
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
    echo 
"$row <br>";




?>
As for the other code posted, the problem was is that it needed a semi-colon ( ; ) after echo $data[logo]
Reply With Quote
  #7  
Old 10-19-2005, 08:52 PM
error_22 error_22 is offline
 
Join Date: Nov 2004
Location: Stockholm, Sweden
Posts: 108
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks so much for your help guys!
Reply With Quote
  #8  
Old 10-19-2005, 10:25 PM
Wired1's Avatar
Wired1 Wired1 is offline
 
Join Date: Nov 2003
Location: Orlando, FL, USA
Posts: 1,361
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, this should work (wrote that other one @ work, no code to reference).

PHP Code:
<?

// Connect to database
$server = 'localhost';
$user = 'user';
$pass = 'pass';
$db_name = 'dbname';
$connection = mysql_connect($server, $user, $pass)
    or die ('I cannot connect to the database because: ' . mysql_error());

$db = mysql_select_db($db_name, $connection)
    or die ('I cannot connect to the database because: ' . mysql_error());


$sql  = "SELECT * FROM logo";

$result = mysql_query($sql);
if ( mysql_error() )
    { print "Database ERROR: " . mysql_error(); }
else
    {
else
    while($row = mysql_fetch_array($result))
{
    echo "$row[column_1_name] | $row[column_2_name] | $row[column_3_name] | etc... <br>";

}
    }//endif else



?>
With this, just replace the column_1_name with the name of the first column, etc.
Reply With Quote
  #9  
Old 10-22-2005, 04:15 PM
error_22 error_22 is offline
 
Join Date: Nov 2004
Location: Stockholm, Sweden
Posts: 108
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks a lot
Reply With Quote
  #10  
Old 11-18-2005, 09:20 PM
error_22 error_22 is offline
 
Join Date: Nov 2004
Location: Stockholm, Sweden
Posts: 108
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It keeps looping.....i get something similar to:

ResultResultResultResultResultResultResult

I just want "Result" to show up one time :/
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 10:13 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04307 seconds
  • Memory Usage 2,284KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (8)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete