473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

PHP Array from mysql table

1
I am currently trying to make a website. I have an array that is for the variable $page. It currently looks like

Expand|Select|Wrap|Line Numbers
  1.  if ($page == logout){include ('logout.php');}
  2.   $pages = array(
  3.  
  4.         'register'        => 'regform.php',
  5.         'verify'        => 'verify.php'
  6.     );
  7.  
  8.     if (array_key_exists($page, $pages))
  9.         include($pages[$page]);
  10.  
I am trying to put all of this into an sql table, which currently looks like

Expand|Select|Wrap|Line Numbers
  1. +----+----------+-------------+
  2. | id | name     | page        |
  3. +----+----------+-------------+
  4. |  1 | register | regform.php |
  5. |  2 | verify   | verify.php  |
  6. +----+----------+-------------+
I have tried a few different pieces of code but so far nothing has worked.

if you can advise, that would be great
Oct 8 '09 #1
1 1960
TheServant
1,168 Expert 1GB
How about a foreach loop? I will do it for MySQL, but logic is the same for SQL...
Expand|Select|Wrap|Line Numbers
  1. $query = "INSERT INTO table (";
  2. $values = " (";
  3.  
  4. foreach($pages as $name=>$page) {
  5. $query .= $name . ", "; // To get: register, verify, etc...
  6. $values .= "'$page', "; // To get: 'regform.php', 'verify.php', etc...
  7. }
  8.  
  9. /* remove last commas and replace with closing brackets */
  10. $query = substr_replace($query ,")",-2);
  11. $values = substr_replace($values ,")",-2);
  12.  
  13. $query_string = $query . $values;
  14.  
  15. /* Run $query_string */
Or something to that effect.
Oct 8 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Richard | last post by:
Hi I have a PHP script which parces a mySQL table and shows which sections meet on which day by using an array containing (mon,...Fri) and another lisitng sections. I then have the PHP do to...
3
by: kiqyou_vf | last post by:
im sort of a newbie to all of this and my terminology isnt accurate but i have a couple simple questions. ive been looking around for a way to insert multiple and seperate strings (like an array or...
5
by: Stephen Preston | last post by:
Trying to load an multidimensional array into a MySQL table with columns as follows, level1,level2,level3,illust,item,description,partNo,qua,price,remarks,weight ,size,mass the array first...
9
by: Dejan | last post by:
Hy, Sorry for my terreble english I have this simple code for deleting rows in mysql table... Everything works fine with it. So, what do i wanna do...: my sql table looks something like...
10
by: eholz1 | last post by:
Hello Members, I am setting up a photo website. I have decided to use PHP and MySQL. I can load jpeg files into the table (medium blob, or even longtext) and get the image(s) to display without...
11
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result =...
12
by: mantrid | last post by:
Hello Can anyone point me in the right direction for the way to read a text file a line at a time and separate the fields on that line and use them as data in an INSERT to add a record to a mysql...
1
by: TechnoAtif | last post by:
Hi to all. I have got a form containing of checkboxes along with other items. I have simply no clue as to (i) how to make entry for those checkbox data into the mysql table . I mean : what query...
2
by: mouac01 | last post by:
Let's say I have this MySQL table. Year Region Amount 2007 West 100 2007 East 200 2007 North 300 2007 South ...
11
AutumnsDecay
by: AutumnsDecay | last post by:
Hey everyone. I have been writing a testimonials backend for a client who wishes to use the feature. How it is supposed to work is like this: The user writes a testimonial of their experience...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.