PHP fetch data from mysql and put it in <select> [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Can anyone please tell me , how to fetch names from mysql through php and then put all those names in hmtl select tag for user to choose one name

use a foreach
echo "<select name='username'>";
while($row=mysql_fetch_array($r))
{
$user=array( $row['fieldname']);
foreach($user as $val)
{
echo "<option value='\$val\'>".$val."</option>";
}
}
echo "</select>";
Hope this helps

Check here.
Hints are
// sql connection here
$query="SELECT * FROM emp";
$result=mysql_query($query);
while($r=mysql_fetch_array($result)
{
echo $r[0];
// all the row that u want to fetch
}

Use PDO. It let's you access the data from SQL which you can then output in a select.

Related

PHP Reading the URL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How do I make the following url to be read:
localhost/index.php?errormsg=wrongpassword
so I want it to set the variable $errormsg to 'wrongpassword' how do I do that? I am pretty sure there is a way using $_GET or $_POST?
You want to use $_GET['errormsg'].
Something like this should do:
if isset($_GET['errormsg'])
{
echo $_GET['errormsg'];
}
$errormsg = $_GET['errormsg']
This should do the trick for you
$_GET['errormsg'] is the answer of your question.
print_r($_GET)
to see all variables in the URL. in this case you want
$_GET['errormsg']
You were as close as ever. A single google would've yielded the answer to you :)
http://php.net/manual/en/reserved.variables.get.php
<?php
// use htmlspecialchars() to clean up url-encoded characters
$error_message = htmlspecialchars($_GET["errormsg"]);
echo 'Error: ' . $error_message;
?>
prints: "Error: error_here", if url = ...?errormsg=error_here

How to display HTML code as HTML code using PHP [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the PHP code as below:
<?php
echo "<tr></tr>";
//ouput I want : <tr></tr>
?>
When Output I want to display <tr></tr>.But I don know whitch function that I should use for this,anyone know help me please,thanks
Try with htmlentities like
<?php
echo htmlentities("<tr></tr>");
?>
Follow this LINK
You can also make use of htmlentities()
<?php
echo htmlentities("<tr></tr>");
?>
Try this
$output = htmlspecialchars("<tr></tr>", ENT_QUOTES);
Use htmlentities
<?php
echo htmlspecialchars('<tr></tr>');
?>

PHP echo same function twice [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to echo a paging function twice,
echo blaetterfunktion($seite, $wieviele_seiten);
content
echo blaetterfunktion($seite, $wieviele_seiten);
I guess that would burden the server twice?
What can I do to have the server burdened just once and still echo it twice?
Place the result of the function in a variable:
<?php
$result = blaetterfunktion($seite, $wieviele_seiten);
echo $result;
?>
content
<?php
echo $result;
?>
Save it to a variable:
<?php
$variable = blaetterfunktion($seite, $wieviele_seiten);
echo $variable;
?>
content
<?php
echo $variable;
?>

Cannot show out results with SUM operator in PHP [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
may I ask for help? I cannot show out the result. If I run the code without the SUM operator, it works properly. Please help, thank you very much.
$sql1 ="SELECT SUM(SeatAmount) FROM reservation
WHERE RsvDate BETWEEN '07/01/2013' AND '07/31/2013'";
$result1 = $con->query($sql1);
printf('<td>');
printf('<b>Seat Amount</b><br/>');
while ($row1 = $result1->fetch_object())
{
printf('
%d<br/>',$row1->SeatAmount);
}
In order for that to work, you'd need an alias:
SELECT SUM(SeatAmount) AS SeatAmount
what is $row1's structure?
You can specify what the sum should be returned as like:
SELECT SUM(SeatAmount) AS SeatAmount
$sql1 ="SELECT SUM(SeatAmount) AS Total FROM reservation
WHERE RsvDate BETWEEN '07/01/2013' AND '07/31/2013'";
$result1 = $con->query($sql1);
printf('<td>');
printf('<b>Seat Amount</b><br/>');
while ($row1 = $result1->fetch_object())
{
printf('
%d<br/>',$row1->Total);
}

How to display stored array from database [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
This is how I'm storing the array into my database (part of a bigger code):
echo '<form action="" method="post">';
for ($count = 0; $count < $_GET["entries"]; $count++)
{
echo 'Enter a beginning to ending date for the week: <input type="text" name="week"><br/>';
}
echo '<input type="submit" name="submit"></form>';
It's within a tag, hence the echo.
I checked my database and I can see the first date, so it is being stored.
This is how I'm displaying my array (doesn't seem to work):
Where am I going wrong? Is it just the output or the input as well? I would really appreciate any suggestions for a possible answer. Thanks.
Current Specific Weeks: <?php
foreach ($currentWeeks as $currentWeeks)
{
echo "{$currentWeeks}\n";
}
Foreach mistake. You're using $currentWeeks for both the array and the element.
Use different variable name in foreach loop
foreach ($currentWeeks as $week)
^^^^^ // here
{
echo "{$week}\n";
}

Categories