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 02-01-2003, 01:32 PM
Graphics's Avatar
Graphics Graphics is offline
 
Join Date: Mar 2002
Posts: 157
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 02-01-2003, 03:02 PM
mr e's Avatar
mr e mr e is offline
 
Join Date: Dec 2001
Posts: 461
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #3  
Old 02-01-2003, 03:05 PM
Graphics's Avatar
Graphics Graphics is offline
 
Join Date: Mar 2002
Posts: 157
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?

EDIT: Or change DESC LIMIT to 4 or above to include extra Itemshops?
Reply With Quote
  #4  
Old 02-01-2003, 03:37 PM
Graphics's Avatar
Graphics Graphics is offline
 
Join Date: Mar 2002
Posts: 157
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #5  
Old 02-01-2003, 04:22 PM
mr e's Avatar
mr e mr e is offline
 
Join Date: Dec 2001
Posts: 461
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

do this for all of them

PHP Code:
$shop_id[$i
i think that should work
Reply With Quote
  #6  
Old 02-02-2003, 12:14 PM
Graphics's Avatar
Graphics Graphics is offline
 
Join Date: Mar 2002
Posts: 157
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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...
Reply With Quote
  #7  
Old 02-02-2003, 01:39 PM
Graphics's Avatar
Graphics Graphics is offline
 
Join Date: Mar 2002
Posts: 157
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Anyone? This is really bugging me and I need answers fast. Gotta finish this by the date...
Reply With Quote
  #8  
Old 02-02-2003, 05:58 PM
mr e's Avatar
mr e mr e is offline
 
Join Date: Dec 2001
Posts: 461
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #9  
Old 02-03-2003, 03:08 PM
Graphics's Avatar
Graphics Graphics is offline
 
Join Date: Mar 2002
Posts: 157
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #10  
Old 02-03-2003, 09:16 PM
mr e's Avatar
mr e mr e is offline
 
Join Date: Dec 2001
Posts: 461
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
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 05:51 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.04525 seconds
  • Memory Usage 2,288KB
  • Queries Executed 13 (?)
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
  • (2)bbcode_code
  • (6)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_postinfo_query
  • fetch_postinfo
  • 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