I want to fetch YouTube embedded link from database and to run in a while loop that its not coming in while loop.
<?php
$video_query=mysqli_query($connect,"select Vdo_SNo, Vdo_Name, Vdo_Category, Vdo_Discription, Vdo_Date from user_videoarena where user_did='3' AND Vdo_Category='Portfolio' ORDER BY Vdo_SNo DESC ");
$i = 1;
while ($video_Row = mysqli_fetch_array($video_query)){
?>
<div class="video_sec fl">
<?php echo $video_Row['Vdo_Name']; ?>
</div><!------------ video_sec -------------------->
<?php $i++; }
?>
With this code only a single video is fetching but not all that is stored in database.
try
<?php
$video_query=mysqli_query($connect,"select Vdo_SNo, Vdo_Name, Vdo_Category, Vdo_Discription, Vdo_Date from user_videoarena where user_did='3' AND Vdo_Category='Portfolio' ORDER BY Vdo_SNo DESC LIMIT 10 ");
while($video_Row = mysqli_fetch_array($video_query)){
?>
<div class="video_sec fl">
<?php echo $video_Row['Vdo_Name']; ?>
</div>
<?php } ?>
If Your record is row-wise in Sql Table then You Have to use a Simple For-loop
First store the result of query in one array.
Then print the array and check the output. If output is same as you want. and if not then you have something mistake in query.
Then simply make a loop like this
for($i=0;$i<count($array_name);$i++){
echo $array[$i]['field name_in_database'];
}
Hope this solution help you.
Related
Enrol table:
From this table I try get value from active_shop
Here I have code:
<?php
$get_config_details = $this->db->get('enrol',$per_page, $this->uri->segment(1));
?>
<?php if ($get_config_details->num_rows() > 0):
foreach($get_config_details->result_array() as $get_config_detail):
$course_details = $this->crud_model->get_course_by_id($get_config_detail['course_id'])->row_array();?>
<?php echo $get_config_detail['active_shop']; ?>
<?php endforeach; ?>
<?php endif; ?>
Now I get the result: 1
But I copied this function from another function. I don't need the foreach function and if and so much code here. I need some simple code to squeeze this table and echo the result. Can anyone help me to correct this code?
The Mysql command is set correctly, since the data is displayed correctly via print_r($ads). I pack the resulting array into $ads
Catch id
$id = htmlentities($_GET['id']);
Query DB.
SELECT
rent.id,
rent.run,
rent.year,
FROM rent
WHERE rent.id = '.$id.'
ORDER BY rent.time_upload DESC');
But through the isset function, they are not shown, no errors are displayed, nothing, just a blank page.
I output the data like this
<?php if (isset($ads)): ?>
<h3>
<?=$ads['id'];?>
<?=$ads['run'];?>
<?=$ads['year'];?>
</h3>
<?php endif; ?>
short_tags are included in PHP.
Please help solve the problem.
You're not going deep enough. $ads['run'] doesn't exist, only $ads['3625']['run'] does. Try:
<?php
foreach( $ads as $ad ) {
?>
<h3>
<?=$ad['id'];?>
<?=$ad['run'];?>
<?=$ad['year'];?>
</h3>
<?php
}
Can anyone help?
My code is like this:
<ol><li>{$student_Value}</li> <ol>'
it gives result:
1. Student101Name
1. Student102Name
1. Student103Name
I want something like:
Student101Name
Student102Name
Student103Name
Please help... Thank you!
Do not close the OL tag every time
OL = Ordered List
LI = List item
If you close and reopen the OL, it creates a new ordered list, and so restarting at 1.
<pre>
echo "<ol>";
foreach loop {
echo "<li>{$student_Value}</li>";
}
echo "</ol>";
</pre>
Good luck.
If you use MySQL to get the data you can add ORDER BY to the query to order the result!
Here more info how to use ORDER BY
And change the HTML Code to be:
<ol>
<li>$student_Value</li>
<li>$student_Value</li>
<li>$student_Value</li>
</ol>
PHP Code will be:
echo "<ol>";
echo " <li> $student_Value </li> ";//write all student values like this
//more student values
echo "</ol>";
It looks like your problem is more CSS related than PHP or SQL.
The reason is probably that your output is:
<ol><li>$student_Value</li></ol>
<ol><li>$student_Value</li></ol>
<ol><li>$student_Value</li></ol>
Each student should be a list item within the ordered list:
<?php
print "<ol>";
while ($row = $result->fetch_assoc())
{
print "<li>{$row['student']}</li>";
}
print "</ol>";
?>
You need something like that
<ol>
<?php
for($i=0; $i<count($studentValue); $i++)
{
?>
<li><?php echo $studentValue[$i]; ?></li>
<?php
}
?>
<ol>
I am giving you above example to tell you that under a 'ol' tag 'li' must be multiple to get your require result.
I need a code that pulls out the listings count for a product in order to have them in the navigation. I am trying to get the product and listing number in the navigation (if there is any), but I don't want to display something if the listings count is equals to 0.
Here follows my code:
<?php if($listingsCount = getListingsCount(0,0,2,2,1,86) > 0): ?>
Bakery
<?php echo $listingsCount['totalRecords'] ?>.
<?php else: ?>
It should be
if ( ($listingsCount = getListingsCount(0,0,2,2,1,86)) > 0)
In this case you the assignment is done first and is then compared to 0. So $listingCount contains the real count.
The way you did it, the comparison is done first and the return value (true/false) is assigned to $listingCount.
Nevertheless. If you never reach the else-part, maybe something in your method getListingsCount() is broken.
Try this:
<?php if (($listingsCount = getListingsCount(0,0,2,2,1,86)) > 0) { ?>
Bakery
<?php echo $listingsCount['totalRecords']; ?>
<?php } else { ?>
Other text
<?php }?>
Thanks guys for your answers. managed to get it working with this...
<?php
$listingsCount = getListingsCount(0,0,2,2,1,86);
if($listingsCount['totalRecords'] > 0):
?>
<dd>
Bakery
[<?php echo $listingsCount['totalRecords'] ?>]
</dd>
<?php endif; ?>
How do you when using custom fields in Wordpress echo just the first value using foreach?
Currently the code is:
<?php for(get_field('venue_event') as $post_object): ?>
<?php echo get_the_title($post_object) ?>
<?php endforeach; ?>
This takes the field from the wordpress page (the field is a link to another page), creates a link to that page using get_permalink but when I want to echo the page title it does it, but then it also echos all other values that are not needed.
If you just want the execute the first iteration of the loop, try this:
<?php foreach(get_field('venue_event') as $post_object): ?>
<?php echo get_the_title($post_object) ?>
<?php break; ?>
<?php endforeach; ?>
Wouldn't it then be easier just to use the first element of the returned array? Maybe Wordpress offers other filters that return the the page's title only.
you can just add
$counter = 0;
<?php for(get_field('venue_event') as $post_object): ?>
$counter++;
if($counter == 1)
{
<?php echo get_the_title($post_object) ?>
}
<?php endforeach; ?>