How to display stored array from database [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
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";
}

Related

How to customize my php echo code? [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 echo some data in the Author Box of my Wordpress Theme with:
<?php echo $user_info->new_user_blond; ?> <?php echo $user_info->new_user_brown; ?> <?php echo $user_info->new_user_red; ?>
The users can check one ore more checkboxes. If a user checks all 3 Checkboxes for example the result shows up in the author box as:
blond brown red
Everthing works fine, but please help me to change my code to achive this result:
blond, brown, red
When i put a "," between the codes it shows me the desired result. BUT if a user
only checks on checkbox it shows me:
blond,,
I would be very pleased if you would support me :)
<?php
$userarr = array(
$user_info->new_user_blond,
$user_info->new_user_brown,
$user_info->new_user_red,
);
$result = implode(',',array_filter($userarr));
echo $result;
?>

PHP fetch data from mysql and put it in <select> [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
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.

Php :Print array inside multi select [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
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
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I want to print the below array inside multi select ;
this is my html code for multi select .
<select name="user_email[]" size="17" style="margin-top:8px; height:256px;" multiple="multiple" class="wiidth300px textBoxStyle removePadding removeMargin externale_users" value="">
This is my array:
$test =array ( [0] => abc#example.com [1] => def#example.com );
i want to print the elements of array html multi select.
<select multiple>
is what you do to select more than one.
http://www.w3schools.com/tags/att_select_multiple.asp
You have to work a lot
you can do this like following:
<?php $array = Array ('kagava,kagava#manutd.com','evra,evra#manutd.com')?>
<select>
<?php
foreach($array as $index=>$email)
{
?>
<option value="<?php echo $email?>"><?php echo $email?></option>
<?php }?>
</select>
this will work surely

Getting value from JSON [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 am struggling to get pull the correct values
I am trying to get the following
packages>items then loop through the ids
{"id":1,"title":"Barnsley","slug":"barnsley","packages":[{"id":1,"title":"Group PACKAGE 1","items"
{"id":9,"title":"Guiness","band_a":null,"band_b":null,"band_c":null,"band_d":null,"band_e":null,"band_f":null,"band_g":null,"band_h":null,"band_i":null,"band_j":null,"variations":null},
{"id":10,"title":"John Smith","band_a":null,"band_b":null,"band_c":null,"band_d":null,"band_e":null,"band_f":null,"band_g":null,"band_h":null,"band_i":null,"band_j":null,"variations":null},
{"id":22,"title":"Chicken Cheese and Bacon Melt","band_a":4.5,"band_b":4.75,"band_c":5.0,"band_d":5.25,"band_e":null,"band_f":null,"band_g":null,"band_h":null,"band_i":null,"band_j":null,"variations":null}],"additional_items":null,"event_types":null}]}
Your JSON isn't valid. You're missing two characters :[ that declare the items array. After fixing the JSON (check it on jsonlint.com) you can iterate over the item IDs like so:
$obj = json_decode($str);
foreach($obj->packages[0]->items as $item)
{
echo $item->id;
}
If there could be more than one package you can iterate those too:
foreach($obj->packages as $package)
{
foreach($package->items as $item)
{
echo $item->id;
}
}

How do i extract a number from a url 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 an SMF website and i'm actually trying to get some header information which includes the title of a particular thread, the url but i've been finding it difficult to get the unique link affixed to the url using PHP.
Here's the url: http://example.com/index.php?topic=6449.msg6858
I'm actually looking for a way to extract the number 6449, I've tried to use the php GET function but it doesn't work.
$parts = explode('.', $_GET['topic']);
echo $parts[0];
// PHP 5.4+
echo explode('.', $_GET['topic'])[0];
See it in action
This would work, too
echo (int) $_GET['topic'];
See it in action
You want to use a combination of substr and strpos (to find the first occurence of a period)
$number = substr($_GET['topic'], 0, strpos($_GET['topic'], '.'));
// 6449
$arr = array();
if (preg_match("/([\\d]+)([.]{1}msg[\\d]+)/", $_GET["topic"], $arr) == 1) {
echo $arr[1];
} else {
trigger_error("not found", E_USER_ERROR);
}

Categories