Load HTML <select> options while loading the page in php/javascript [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
How to load option dynamically,when we have to load options like eg: 1-500. as the values in select list.
Loding can be either done in php or javascript.
plz can someone provide eg/simple snippet or helpfull links? Thanks!
I tried: Javascript
for(var i=1;i<=500;i++)
{
//create new option
var option = new Option(i, "Value" + i);
//Add the new option it to the select
sel.options[i] = option;
}

Iterate over the values with a foreach, for or while loop, and just ouput whatever you need:
<?php
$html = '<select>';
for ($i=0; $i<500; $i++) {
$html .= '<option value="' . $i . '">Option ' . $i . '</option>';
}
$html .= '</select>';
echo $html;
?>

Related

php string two echo statements together [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
this string is breaking my code and I am not sure why. If anyone can help me correct it I would appreciate it.
if ($p == $url) { echo '<li><a class="active" href="index.php?p=' . $url . '">'
. $label . '</a></li>'; } else { echo '<li>' . $label . '</li>'; }
htmlspecialchars(urlencode($url)) and htmlspecialchars($label). The rest seems fine.

PHP Manipulating MySQL Results? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
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
Improve this question
I need some little help on a simple thing!
I have this table in my database, where I have a number of images stored, called "covers".
And then I have a table in HTML that displays the covers of this MySQL table inside one of it's cells.
Like this:
<td><a href="movie.php?id=<?php echo $idt + 1; ?>">
<?php echo '<img src="'.htmlentities($idt + 1['cover'], ENT_QUOTES, 'UTF-8').'" alt="Cover" style="max-width:300px;max-height:300px;" />';; ?></a></td>
And this is the code before
$req = mysql_query("select id, name, year, genre, cover from movies");
$dnn = mysql_fetch_array($req);
$idt = $dnn['id'];
But why doesn't it work when I try to dynamically change id by putting this?
$idt + 1;
In order to output data from multiple rows, I suggest using a loop like this:
while ($row = mysql_fetch_assoc($req)) {
?><td>
<a href="movie.php?id=<?php echo $row['id']; ?>">
<img src="<?php echo htmlentities($row['cover'], ENT_QUOTES, 'UTF-8'); ?>" alt="Cover" />
</a>
</td><?php
}
You need to fetch a whole set of results and not just one id and increment it in the view. You should do a foreach loop on $idt like that:
foreach($dnn as $row){
$id=$row['id'];
$cover=$row['cover'];
$genre=$row['genre'];
//etc...
//now echo html with vars like this:
echo "<img src=\"$cover\"/>";
}

how to search using a textfield? php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
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
Improve this question
I want to search a whole news feed by inserting a word in my text field. I have no idea how to do this. Here is my code, so you know what I mean with it.
<form action="search.php" method="get">
<tr><th>search: </th><td><input type="text" name="search" value="{$word}"></td></tr>
</form>
How can I check if the word I inserted in the searchbar, exists somewhere in the news feed?
My news feed is used like this:
$xml=simplexml_load_file("newsfeed.xml");
foreach($xml->channel->item as $item) {
echo '<h1 class="title">' . $item->title . '</h1>';
echo '<p class="desc">'.$item->description."</p>";
}
I think you can use the function strpos.
Find the numeric position of the first occurrence of needle in the
haystack string.
Example:
$a = 'Long text to look into it.'
if (strpos($a, 'it') !== false)
echo 'true';
In your case, you can use strpos either to find the word in the item title or the item description:
$a = $_GET['search'];
foreach($xml->channel->item as $item) {
print_result = 0; // flag to know if the search is in the feed.
if (strpos($item->description, $a) !== false){
print_result = 1;
} // end if desc
if (strpos($item->title, $a) !== false){
print_result = 1;
} // end if title
if(print_result == 1){
echo '<h1 class="title">' . $item->title . '</h1>';
echo '<p class="desc">'.$item->description."</p>";
} //end if print results.
} // end foreach
I would make a foreach like you do it now:
And make kind of relevance points for each news item. Something like if it's in the title then it's more relevant and if it's at the beginning and so on.
Then you can write it into an array and sort it.
I hope you have something like an id in your newsfeed.xml for this.

add inline style to div tag 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
The following code has no problem, I just need to add an inline style as
<div id="nav-menu" style="width:65px;"> to it. I need your help to include that style.
<?php
$pages = array('health.php' => 'Health',
'weightloss.php' => 'Weight Loss',
'fitness.php' => 'Fitness',
'sex.php' => 'Sex',
'mindbody.php' => 'Mind-Body',
'food.php' => 'Food',
'beauty.php' => 'Beauty',
'more.php' => 'More');
echo "<div id=\"nav-menu\">\n";
// let's create a unordered list to display the items
echo "<ul>";
// here's where all the items get printed
foreach ($pages as $Listing) {
echo "<li>$Listing</li>\n";
}
// closing the unordered list
echo "</ul>";
echo "</div>\n";
?>
Do you mean this?
echo "<div id=\"nav-menu\" style=\"width:65px;\">\n";
OR
echo "<div id='nav-menu' style='width:65px;'>\n";
OR
echo '<div id="nav-menu" style="width:65px;">' . "\n";
echo "<div id=\"nav-menu\" style=\"width:65px;\">\n";
echo '<div id="nav-menu" style="width:65px;">';
By default you cannot set a width for a block element like <div>; it takes up the full width of its container.
try: echo "<div id=\"nav-menu\" style=\"width:65px;display:inline-block;\">\n";

MYSQL Php parsing error [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 unable to figure out the parsing error on this piece of code.
Any help would be greatly appreciated.
echo "<li>";
echo "<a href=\"http://online.somewebsite.com/" . $info['path'] . >" . $info['value'] . "</a>";
echo "</li>";
echo '<li>' . $info['value'] . '</li>';
You forget " before > in second line
echo "<li>";
echo "" . $info['value'] . "";
echo "</li>";

Categories