Jump to content

Recommended Posts

if i want to use the $podcast_programming_exspertise varable to insert to a database,

 

how can i post it to the database without sticking the insert query inside the loop.

 

<?php
if($_POST['podcast_programming_exspertise']){foreach($_POST['podcast_programming_exspertise'] as $podcast_programming_exspertise) {

//dont want a database query here what my option's	

     echo  "$podcast_programming_exspertise <br><br>";
}}
><

 

because there around 100 off foreach on the page i need a way to get the info in the database.

 

the data comes out lovely with around 10 different words but i need a way to post the variable in it coded way but not adding a insert in the current code.

 

The way it works, is a user get to answer questions via a form the form is arrayed to get all the questions.

Link to comment
https://forums.phpfreaks.com/topic/146659-solved-post-help-with-foraech-array/
Share on other sites

Erm.. What!

I guess you could use MySQLi and implode the array!

but the simple truth is if you want to insert a 100 rows then you need to insert 100 rows!

 

If you gave reasoning why you don't want to do it this why may help!

sorry i was told that if you use a loop with a sql query it bad.

 

sorry i read this on here from users, that suppose to be experts going buy that.

 

Yeah, and those few sentenses make heaps of sense too.

 

PHP's mysql extension will not let you execute multiple queries at once so (depending on your database schema) it is likely you need to execute mltiple quiries within a loop.

 

We need to see your database schema however and a small example of some data.

if you need to insert 100 rows every post or 5 minutes then yeah it will overload your SQL server, its about the design of the system! but your question was how can i insert 100 records without using inserting 100 records..

 

Now you may want to look into MySQLI,

 

you could structor your SQL query like this

INSERT INTO `list1` (`ID`, `Name`) VALUES
(1, 'Dogs'),
(2, 'Trees'),
(3, 'Apples');

but thats more SQL than PHP, i won't insert more than 50 records like that but that would mean you need to open 2 connections instead of 100

 

Either way it depends on the design..

For example the statment above would insert 3 records, now you could assume thats more data then 1 record! but not if the one records contains an 16gb Blog!.. again its all about the design!

what do i do to get the info in the database correctly.

 

do i create a function for the insert then add that function inside the loop's

 

a and b and c got 10 quistions.

 

the databse type is text as abc will go in with the 10 answers with a space.

<?php


if($_POST['a']){foreach($_POST['a'] as $a) {

   //dont want a database query here what my option's   

        echo  "$a <br><br>";
   }}
   
   if($_POST['b']){foreach($_POST['b'] as $b) {

   //dont want a database query here what my option's   

        echo  "$b <br><br>";
   }}
   
     if($_POST['c']){foreach($_POST['c'] as $b) {

   //dont want a database query here what my option's   

        echo  "$c <br><br>";
   }}
   
   
   ?>
   
   //form example only
   
   <input type="radio" name="a[]" value="yes" checked>Yes.
<br>
<input type="radio" name="a[]" value="no">No.
   

   <input type="radio" name="b[]" value="yes" checked>Yes.
<br>
<input type="radio" name="b[]" value="no">No.


<input type="radio" name="c[]" value="yes" checked>Yes.
<br>
<input type="radio" name="c[]" value="no">No.

here the full code so you can see my point.

no insert added yet don't no how to because off all the foreach data

 

every think works just need to get me head around getting the info in the database correctly and safely.

 

The information is echoed out so i no all the array and variables work.

 

i no that i need to add a insert where the echo is , but need to no how with all the foreach there.

 

the way the info comes from the form is good but now need to get rid off the echo and insert to database.

<?php session_start();

include("php_podcast_header.php");
require_once("php_podcast_function.php");



if(isset($_POST['submit'])){

$podcast_username=$_POST['podcast_username'];
$podcast_password=$_POST['podcast_password'];
$podcast_email_address=$_POST['podcast_email_address'];
$podcast_programming_name=$_POST['podcast_programming_name'];
$podcast_programming_years=$_POST['podcast_programming_years'];
$podcast_programming_pay_hour=$_POST['podcast_programming_pay_hour'];




echo" username is\n <br>$podcast_username <br><br>
      password is\n <br>$podcast_password <br><br>
      email address is\n <br>$podcast_email_address<br><br>
      profile name is\n <br>$podcast_programming_name<br><br>
      programming years\n <br>$podcast_programming_years<br><br>
      
      programming skils\n <br>";
if($_POST['podcast_programming_exspertise']){foreach($_POST['podcast_programming_exspertise'] as $podcast_programming_exspertise) {

     echo  "$podcast_programming_exspertise <br><br>";
}}

echo"podcast contubute\n <br>";
if($_POST['podcast_programming_contubute']){foreach($_POST['podcast_programming_contubute'] as $podcast_programming_contubute) {
	echo  "$podcast_programming_contubute <br><br>";
}}

echo"user for hire\n <br>";
if($_POST['podcast_programming_hire']){foreach($_POST['podcast_programming_hire'] as $podcast_programming_hire) {
	echo  "$podcast_programming_hire <br><br>";
}}

echo"can user contact you via built in messager\n <br>";
if($_POST['podcast_programming_built_in_email']){foreach($_POST['podcast_programming_built_in_email'] as $podcast_programming_built_in_email) {
	echo  "$podcast_programming_built_in_email <br><br>";
}}

echo"can user contact you via your vaild email address\n <br>";
if($_POST['podcast_programming_out_side_email']){foreach($_POST['podcast_programming_out_side_email'] as $podcast_programming_out_side_email) {
	echo  "$podcast_programming_out_side_email <br><br>";
}}

echo"show email on profile\n <br>";
if($_POST['podcast_programming_show_email']){foreach($_POST['podcast_programming_show_email'] as $podcast_programming_show_email) {
	echo  "$podcast_programming_show_email <br><br>";
}}

echo"teach users for free\n <br>";
if($_POST['podcast_programming_teach_free']){foreach($_POST['podcast_programming_teach_free'] as $podcast_programming_teach_free) {
	echo  "$podcast_programming_teach_free<br><br>";
}}

echo"teach users for a price\n <br>";
if($_POST['podcast_programming_teach_pay']){foreach($_POST['podcast_programming_teach_pay'] as $podcast_programming_teach_pay) {
	echo  "$podcast_programming_teach_pay<br><br>";
}}

echo" how much you charge per hour\n  <br> £$podcast_programming_pay_hour <br>";

echo"do you agree with terms and condition\n <br>";
if($_POST['podcast_programming_agrement']){foreach($_POST['podcast_programming_agrement'] as $podcast_programming_agrement) {
	echo  "$podcast_programming_agrement<br><br>";
}}



}

?>

<br>

<form method="POST" Action="<?php $_SERVER['PHP_SELF']; ?>">

<table STYLE=" width: 900px; height: 50%; border: 0; margin-left: auto; margin-right: auto;">
<tr>
<td valign="top"  STYLE=" text-align: center; background-color: #3366ff; width: 25%; ">
<br><br>
<b>Username</b><br>
4 letters & 4 numbers.
<br>
<input type="text" name="podcast_username">
<br><br>
<b>Password</b><br>
3 letters & 3 numbers.
<br>
<input type="password" name="podcast_password">
<br><br>
<b>Email Address</b><br>
Valid email address.
<br>
<input type="text" name="podcast_email_address">
<br><br>
<b>Profile Username</b><br>
Name shown to others.
<br>
<input type="text" name="podcast_programming_name">
<br><br>
</td>

<td  valign="top" STYLE="text-align: center; background-color: #3366ff; width: 25%;">

<br><br>

<b>Programming Years</b>
<br><br>
Years Programming.
<br>
<select name="podcast_programming_years">
<option value=''>Select:</option>
<?php
for($py=1; $py<51; $py++){
echo"<option value='$py'>$py</option>";
}
?>
</select>

<br><br>

<b>Programming Exspertise</b><br><br>
Your programming skills.
<br>


<div align="left">

<input type="checkbox" name="podcast_programming_exspertise[]" value="Html  "> Html.
<br>
<input type="checkbox" name="podcast_programming_exspertise[]" value="Xhtml  "> Xhtml.
<br>
<input type="checkbox" name="podcast_programming_exspertise[]" value="Css  "> Css.
<br>
<input type="checkbox" name="podcast_programming_exspertise[]" value="Javascript  "> Javascript.
<br>
<input type="checkbox" name="podcast_programming_exspertise[]" value="Php  "> Php.
<br>
<input type="checkbox" name="podcast_programming_exspertise[]" value="Mysql  "> mysql.
<br>
<input type="checkbox" name="podcast_programming_exspertise[]" value="+ Others  "> +Others.
<br>
</div>

</td>
<td  valign="top" STYLE="text-align: center; background-color: #3366ff; width: 25%;">

<br><br>

<b>Web site contubute </b>
<br><br>
Going to contubute.
<br>
<br>
<div align="left">

<input type="checkbox" name="podcast_programming_contubute[]" value="Recorded Pod Cast  ">Recorded Pod Cast.
<br>
<input type="checkbox" name="podcast_programming_contubute[]" value="video Pod Cast  ">video Pod Cast.
<br>
<input type="checkbox" name="podcast_programming_contubute[]" value="Tutoral Pod Cast  ">Tutoral Pod Cast.
<br>
<input type="checkbox" name="podcast_programming_contubute[]" value="Shop">Shop.
<br>
<input type="checkbox" name="podcast_programming_contubute[]" value="Teach Programming  ">Teach Programming.
<br>
</div>
<br>
<b>Are you for hire</b>
<br>
Let users no your for hire.
<br><br>
<input type="radio" name="podcast_programming_hire[]" value="yes" checked>Yes.
<br>
<input type="radio" name="podcast_programming_hire[]" value="no">No.
<br>

</td>

<td  valign="top" STYLE="text-align: center; background-color: #3366ff; width: 25%;">

<br><br>

<b>Can users contact you</b>
<br><br>
Built in messenger.
<br><br>
<input type="radio" name="podcast_programming_built_in_email[]" value="yes" checked>Yes.
<br>
<input type="radio" name="podcast_programming_built_in_email[]" value="no">No.
<br>
<br>
<br><br>
<b>Can users email you</b>
<br><br>
Live mail.
<br><br>
<input type="radio" name="podcast_programming_out_side_email[]" value="yes" checked>Yes.
<br>
<input type="radio" name="podcast_programming_out_side_email[]" value="no">No.


</td>
</tr></table>

<br><br>

<table STYLE=" width: 900px; height: 50%; border: 0; margin-left: auto; margin-right: auto;">
<tr>
<td valign="top"  STYLE=" text-align: center; background-color: #3366ff; width: 25%; ">
<br><br>
<b>Show your email</b><br><br>
Show email on profile.
<br><br>
<input type="radio" name="podcast_programming_show_email[]" value="yes" checked>yes.
<br>
<input type="radio" name="podcast_programming_show_email[]" value="no">No.
<br>
<br>

</td>

<td  valign="top" STYLE="text-align: center; background-color: #3366ff; width: 25%;">
<br><br> 
<b>Teach for free</b><br><br>
Teach others for free.
<br><br>
<input type="radio" name="podcast_programming_teach_free[]" value="yes" checked>yes.
<br>
<input type="radio" name="podcast_programming_teach_free[]" value="no">No.
<br>
<br>
</td>
<td  valign="top" STYLE="text-align: center; background-color: #3366ff; width: 25%;">
<br><br>
<b>Pay to teach</b><br><br>
Pay money to teach.
<br><br>
<input type="radio" name="podcast_programming_teach_pay[]" value="yes" checked>yes.
<br>
<input type="radio" name="podcast_programming_teach_pay[]" value="no">No.
<br>
<br>
</td>

<td  valign="top" STYLE="text-align: center; background-color: #3366ff; width: 25%;">
<br><br>

<b>How much you charge</b><br><br>
How much money per hour <br>
to teach others.
<br><br>
£ <select name="podcast_programming_pay_hour">
<option value=''>Select:</option>
<?php
for($py=1; $py<51; $py++){
echo"<option value='$py'>$py</option>";
}
?>
</select>
<br><br>
</td>
</tr></table>

<br><br>

<table STYLE=" width: 900px; height: 50%; border: 0; margin-left: auto; margin-right: auto;">
<tr>
<td valign="top"  STYLE=" text-align: center; background-color: #3366ff; width: 75%; ">

<textarea readonly STYLE="border: 0; text-align: left; background-color: #3366ff;" cols="80" rows="10" name="" ><?php include("php_podcast_terms.php")?></textarea>
</td>

<td  valign="top" STYLE="text-align: center; background-color: #3366ff; width: 25%;">
<br><br>
<b>Terms And Conditions</b><br><br>
Do you agree to the terms and conditions.
<br><br>
<input type="radio" name="podcast_programming_agrement[]" value="yes" checked>yes.
<br>
<input type="radio" name="podcast_programming_agrement[]" value="no">No.

<br><br>
</td>
</tr></table>

<br><br>

<table STYLE=" width: 900px; height: 50%; border: 0; margin-left: auto; margin-right: auto;">
<tr>
<td valign="top"  STYLE=" text-align: center; background-color: #3366ff; width: 100%; ">
<br><br>
<input type="submit" name="submit" value="Register Me!">
<br><br>
</tr></table>

</form>

<?php include("php_podcast_footer.php");?>

</body>

</html

thank you sasa, can you kindly explain the implode bit, i no what implode  does but,

how it imploding "' <<< don't get.

 

and get the format you have done.

 

need to learn it and understand properly.

 

it much better then foreach.

 

cheers.

 

current result

('Html  '), ('Xhtml  '), ('Css  '), ('Javascript  '), ('Php  '), ('Mysql  '), ('+ Others  ')

sorry i forgot the $_POST[''] within the implode .

 

 

got very confused but cheers mate.

 

i came up with a faster way to show the info works well.

<?php
if(isset($_POST['submit'])){

$pt[]=$_POST['podcast_username'];
$pt[]=$_POST['podcast_password'];
$pt[]=$_POST['podcast_email_address'];
$pt[]=$_POST['podcast_programming_name'];
$pt[]=$_POST['podcast_programming_years'];
$pt[]=implode(',',$_POST['podcast_programming_exspertise']);
$pt[]=implode(',',$_POST['podcast_programming_contubute']);
$pt[]=implode(',',$_POST['podcast_programming_hire']);
$pt[]=implode(',',$_POST['podcast_programming_built_in_email']);
$pt[]=implode(',',$_POST['podcast_programming_out_side_email']);
$pt[]=implode(',',$_POST['podcast_programming_show_email']);
$pt[]=implode(',',$_POST['podcast_programming_teach_free']);
$pt[]=implode(',',$_POST['podcast_programming_teach_pay']);
$pt[]='£'.$_POST['podcast_programming_pay_hour'];
$pt[]=implode(',',$_POST['podcast_programming_agrement']);

$title=array("Username","Password","Email","Programmming Name","Years Programming",
"Your Programming Exspertise","Contubute To Others","Are You For Hire","Can user contact you with the bult in messanger","Can users email you valid email address",
"Show your email on your profile","Would you teach users for free","do you charge to tech your skill","If you charge how much per hour","Do you agree to the agreement");


for($i=0; $i<count($title); $pt++, $i++){

	echo " <b>{$title[$i]}:</b>\n <br> {$pt[$i]}\n <br>";
}

}
           ?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.