vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   MySQL/PHP Variable Question (https://vborg.vbsupport.ru/showthread.php?t=48394)

Graphics 02-01-2003 01:32 PM

MySQL/PHP Variable Question
 
OK, I'm making my own Itemshop. But I'm not the best coder around and need some help with something simple.

I need multiple things to show up from the same MySQL table column. For example, here's a part of my file:

Code:

// select information
$shop_id    = $DB_site->query("SELECT shop_id FROM itemshops");
$shop_name  = $DB_site->query("SELECT shop_name FROM itemshops");
$shop_image  = $DB_site->query("SELECT shop_image FROM itemshops");
$shop_rating = $DB_site->query("SELECT shop_rating FROM itemshops");
$shop_profit = $DB_site->query("SELECT shop_profit FROM itemshops");
$shop_total  = $DB_site->query("SELECT shop_total FROM itemshops");

Now, if I have, for example, 3 Itemshops, how would I get the three Itemshop's attributes to show? Use the variables three times? :ermm:

Thanks.

mr e 02-01-2003 03:02 PM

here try this

PHP Code:

$shops $DB_site->query("SELECT * FROM itemshops DESC LIMIT 3");
while (
$shop $DB_site->fetch_array($shops)) {
        
$i 1;
        
$shop_id$i $shop[shop_id];
        
$shop_name$i $shop[shop_name];
        
$shop_image$i $shop[shop_image];
        
$shop_rating$i $shop[shop_rating];
        
$shop_profit$i $shop[shop_profit];
        
$shop_total$i $shop[shop_total];
        
$i++;


that will select the first 3 rows from your database and put each variable into for example

$shop_id1 will be the first shops id
and
$shop_total2 will be the second shops total

im pretty sure this should work

Graphics 02-01-2003 03:05 PM

So then for the other Itemshops I'd just simply repeat that except change the value of $i to 2?

Or am I getting this wrong? :p

EDIT: Or change DESC LIMIT to 4 or above to include extra Itemshops?

Graphics 02-01-2003 03:37 PM

OK, this is me testing your method.

PHP Code:

<?php

require("./global.php");

$shops $DB_site->query("SELECT * FROM itemshops DESC LIMIT 3");
while (
$shop $DB_site->fetch_array($shops)) {
        
$i 1;
        
$shop_id$i $shop[shop_id];
        
$shop_name$i $shop[shop_name];
        
$shop_image$i $shop[shop_image];
        
$shop_rating$i $shop[shop_rating];
        
$shop_profit$i $shop[shop_profit];
        
$shop_total$i $shop[shop_total];
        
$i++;
}
?>
<html>
<head>
</head>
<body>
$shop_name2</body></html>

But I get an error:

PHP Code:

Parse errorparse errorunexpected T_VARIABLE in /home/virtual/site139/fst/home/staticnetwork/public_html/forum/test.php on line 8 

:(:( Any ideas? Gurus? ;)

mr e 02-01-2003 04:22 PM

do this for all of them

PHP Code:

$shop_id[$i

i think that should work

Graphics 02-02-2003 12:14 PM

Hmmm... Well Here's my full file:

PHP Code:

<?php

require("./global.php");

$shops $DB_site->query("SELECT * FROM itemshops"); 
while (
$shop $DB_site->fetch_array($shops)) { 
$i 1
$shop_id[$i] = $shop[shop_id]; 
$shop_name[$i] = $shop[shop_name]; 
$shop_image[$i] = $shop[shop_image]; 
$shop_rating[$i] = $shop[shop_rating]; 
$shop_profit[$i] = $shop[shop_profit]; 
$shop_total[$i] = $shop[shop_total]; 
$i++; 
}
?>
<html>
<head>
</head>
<body>
<?php
echo "$shop_id[$i]";
?>
</body></html>

But it just doesn't show anything at all when I load up the page... :(

Graphics 02-02-2003 01:39 PM

Anyone? This is really bugging me and I need answers fast. ;) Gotta finish this by the date... :(

mr e 02-02-2003 05:58 PM

you can't echo $shop_id[$i], it has to be $shop_id[0] or [1] etc, but are you going to use these variables in repeating rows or at all different parts of the page? like are you going to use $shop_id[0] at one part and $shop_id[1] in some completely different part?

Graphics 02-03-2003 03:08 PM

It's be like:

Code:

<tr>
 <td>
  $shop_id[0]
 </td>
</tr>
<tr>
 <td>
  $shop_id[1]
 </td>
</tr>

So they're not that far away. What's the diffrence anyway?

mr e 02-03-2003 09:16 PM

because if your going to do this in repeating rows there is a much easier way, this way lets you use these variables anywhere you want, if you want to do repeating rows, ex:
$shopid1, $shopname1 etc
$shopid2, $shopname2 etc

then do

PHP Code:

$shops $DB_site->query("SELECT * FROM itemshops DESC LIMIT 3");
while (
$shop $DB_site->fetch_array($shops)) {
     print 
"<tr><td>$shop[shop_id]</td><td>$shop[shop_name]</td></tr>"


this will print table rows with the shop id and shop name in the td's until the DESC LIMIT is reached or the end of your db

Graphics 02-04-2003 03:16 PM

Thanks man you rule! :)


All times are GMT. The time now is 01:01 PM.

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.01090 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
  • (2)bbcode_code_printable
  • (6)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (11)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete