TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Millions of actions from one variable? (http://www.talkphp.com/absolute-beginners/1803-millions-actions-one-variable.html)

Aaron 12-27-2007 08:42 AM

Millions of actions from one variable?
 
Okay... I was wondering about this... you have an item. The item costs a dollar. you make several hundred things displaying the item all over your site in different fashions. You change the price all over your site by editing the variable $price


you want to add another item, and plan to keep adding items and changing attributes regularly. what would be the easiest way? Arrays and foreach statements littered across the code? some kind of OOP thing (I have not the slightest clue how to use OOP?) This sounds like a gallery system...

sjaq 12-27-2007 01:29 PM

You should dive into MySQL(i).. PHP: MySQL - Manual or PHP: mysqli - Manual and maybe some tutorials Google

Aaron 12-27-2007 04:56 PM

I know you're trying to help, but saying "MySQL is the answer" doesn't help me. I was going to get into MySQL when I started to make the member system I wanted to make.

Village Idiot 12-27-2007 05:27 PM

A database is your best solution. If you dont want to use a database, arrays are your next best option.

Aaron 12-27-2007 06:56 PM

... HOW would I use a database? This is like throwing me out in the desert and saying "water is at an oasis". How would I use a database to update 20+ pages with a new block of code that has the information of the block of code?

like... TACO:
price: $3.00 USD
size: XL

and then 20 pages display that (in different fashions...)
but I want to duplicate the same way it was displayed on all those pages, INCLUDING giving it it's own new page if that needs to be done, just by adding

taco 2
price: free
size: XXL
taste: yummy.

I appreciate the help, but... It is just confusing me more.

sjaq 12-27-2007 08:00 PM

There are lots of tutorials on the web, I gave you a google search with loads of tutorials. It would be such a waste of time to write another one when there are loads of excellent ones on the web.

read this...

Aaron 12-27-2007 08:16 PM

All I can say is that that doesn't help me at all. I know what MySQL is. I am asking HOW not WHAT.

Quote:

Originally Posted by sjaq (Post 7196)
You should dive into MySQL(i).. PHP: MySQL - Manual or PHP: mysqli - Manual and maybe some tutorials Google

Quote:

Originally Posted by Aaron (Post 7199)
I know you're trying to help, but saying "MySQL is the answer" doesn't help me. I was going to get into MySQL when I started to make the member system I wanted to make.

Quote:

Originally Posted by Village Idiot (Post 7202)
A database is your best solution. If you dont want to use a database, arrays are your next best option.

You basically said the same thing over and over after I said it didn't help.

Lets repeat this for the third time if you don't get it:

There is a code that makes a box on a page called "blue". The box has information in it. Hell, the box fetches information from a MySQL table. Now, there are a whole bunch of pages that do something and display the information in the SQL table.

How would I make it so the function does itself again if there are two tables of information?

(I really hope I don't sound like an asshole here, but this is driving me nuts.)

sjaq 12-27-2007 08:43 PM

Ok, I'm sorry but it sounded like you didn't knew what MySQL was...

How do you mean "if there are to tables of information"? Or do you mean rows?

Aaron 12-27-2007 08:58 PM

Well...
Each row stores a value, and each column stores a value for that value, right?

so table taco
price 2.45
size xl

and then table taco 2
price 3.56
sixe xxl


Well, there are probably more ways to do that O.o I haven't gotten too far into MySQL. You know what... I'm gonna go get something to eat...

sjaq 12-27-2007 09:11 PM

So you really don't understand the use of MySQL if you don't know how to do that :-P

But here's a basic script that does what I think you want to do..
First there is the database structure:

and the database content:


The script:
PHP Code:

<?php 

    $connection 
mysql_connect('localhost''root') or die('database connection failed: 'mysql_error());
                 @
mysql_select_db('testing'$connection);
    
    
$query mysql_query('SELECT * FROM test_row') or die(mysql_error());
    
    while(
$row mysql_fetch_object($query)) {
        print 
'<h2>'$row->name .'</h2>'"\n";
        print 
'<h3>price: $ '$row->price .'</h3>'"\n";
        print 
'<p>'$row->description .'</p>' "\n";
    }
    
    
mysql_free_result($query);
    
mysql_close($connection);

?>

Which produces:
HTML Code:

<h2>iPod nano</h2>
<h3>price: $ 400</h3>
<p>Some iPod description here</p>
<h2>MacBook Pro</h2>
<h3>price: $ 3000</h3>
<p>MacBook Pro description here</p>
<h2>Towel</h2>
<h3>price: $ 15</h3>
<p>This is a awesome towel! (it has dolphins on it!)</p>

Hope you see how to use MySQL now..

Village Idiot 12-27-2007 11:08 PM

Its like an excel spreadsheet.

Dr John 12-27-2007 11:23 PM

Aaron, I strongly suggest you get a big fat book on PHP and MySQL, AND a slim book on the same topic AND a slim one on database theory and design. Read the thin ones first, from cover to cover. Then start of the thick book (as the thin ones will only give you a few ideas to get started) and read as much of it as possible.

THEN, when you've tried a lot of the examples/exercises in these all books, attempt your project.

I'm not being funny, database theory is a big subject, and it's clear you need a lot more background knowledge to make progress. And that knowledge is locked up in textbooks, not in a few lines of a reply in a forum.

Aaron 12-29-2007 06:03 AM

I still need to lounge through PHP and MySQL for dummies third edition. And that is after PHP 5 for dummies. After that what books will you suggest? (I only get the dummies books because they are free.)


All times are GMT. The time now is 06:47 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0