vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   get information from database (https://vborg.vbsupport.ru/showthread.php?t=98779)

error_22 10-19-2005 02:24 PM

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

peterska2 10-19-2005 02:31 PM

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

error_22 10-19-2005 02:43 PM

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

SELECT logo * FROM logo

:ermm:

CommuneZoom 10-19-2005 03:21 PM

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]



error_22 10-19-2005 05:02 PM

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!

Wired1 10-19-2005 05:46 PM

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]

error_22 10-19-2005 07:52 PM

Thanks so much for your help guys!

Wired1 10-19-2005 09:25 PM

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.

error_22 10-22-2005 03:15 PM

thanks a lot :)

error_22 11-18-2005 09:20 PM

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

ResultResultResultResultResultResultResult

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


All times are GMT. The time now is 04:52 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01720 seconds
  • Memory Usage 1,760KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (8)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete