Jump to content

php beginer


lioslios

Recommended Posts

hello guys im beginer with php

sory for my simple and first step questions

 

i have create a page that reads some data from an sql table and displays them, this works but i have some questions

 

1st the mysql_select_db($db)or die(mysql_error()); means if some error ocoure the connection will close or the entire web pages closes??

 

2st is some way to create for each record a dynamic submit button with button text the name of the record?

 

eg

 

id  name

1    george

2    nick

3    liana

 

 

 

so to create 3 submit buttons with names  george  nick liana and when i press any button to make an acion

 

 

thanks

Link to comment
Share on other sites

with the submit buttons, add a value to each of them, so your form might be:

<form action='action.php' method='POST'>
<input type="text" name="text">
<input type="submit" name="name" value="george">
<input type="submit" name="name" value="nick">
<input type="submit" name="name" value="liana">
</form>

and your php would look like

<?php
if($_POST['name'] == "george"){
//execute this code
}
if($_POST['name'] == "nick"){
//execute this code
}
if($_POST['name'] == "liana"){
//execute this code
}
?>

However, if you want the names to be dynamically gotten from the mysql database, you must customize the commands to take that into consideration, for example if you wanted to delete the row, you would have the following code

<?php
//add link data
mysql_query("DELETE FROM users WHERE username = '$_POST['name']'");
echo "{$_POST['name']} deleted";

If you want to get the usernames for the submit buttons dynamically also, you will need something like this

$result =  mysql_query("SELECT * from users WHERE max(`id`)");
while($row = mysql_fetch_array($result)){
$max = $row['id'];
}
//start submit buttons
if($max > 1)
mysql_query("SELECT * FROM users WHERE id = '1'");
while($row = mysql_fetch_array($result)){
echo "<input type='submit' name='name' value='$row[username]'>";
$newvalue = 2
}
//include this in another file and require it as many times as necessary
if($max > $newvalue)
mysql_query("SELECT * FROM users WHERE id = '$newvalue'");
while($row = mysql_fetch_array($result)){
echo "<input type='submit' name='name' value='$row[username]'>";
}
$n = $newvalue;
$newvalue = $n+1;
//require this several times
?>

 

 

Link to comment
Share on other sites

yes AyKay47 you write about drop down

 

but this web application i wand to acsses from my android acer iconia a500 so i beleve the submint buttons ar more easy with the touch screen, if you have in mind some other control exept buttons but touch screen frienly please tellme!!!

 

in the beginig of the post i have ask about mysql_select_db($db)or die(mysql_error());

 

i say this because when i reload the page some times the browser closes-crashes but this happens only in iconia , in  my desktop dont have this problem, so im thinking for data loss from wireless or iconia browser bug, if you have any idea for this please help me

 

many many thanks

 

Link to comment
Share on other sites

yes AyKay47 you write about drop down

 

but this web application i wand to acsses from my android acer iconia a500 so i beleve the submint buttons ar more easy with the touch screen, if you have in mind some other control exept buttons but touch screen frienly please tellme!!!

 

in the beginig of the post i have ask about mysql_select_db($db)or die(mysql_error());

 

i say this because when i reload the page some times the browser closes-crashes but this happens only in iconia , in  my desktop dont have this problem, so im thinking for data loss from wireless or iconia browser bug, if you have any idea for this please help me

 

many many thanks

I posted a link to the die() function documentation, everything you need to know about the function is there.

Drop downs work fine on mobile devices.

Link to comment
Share on other sites

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.