How to hide id and display their name's instead? - php

I don't how to hide the id of the running candidates which is candid, I can't remove in the value because it will handle the votes of the candidates I really need some help or any solution. I want that it will display the names in the preview.php and hide the id but don't know how?
Here's the code of plsvote.php:
value="<?php echo $rows['candid'] . "-" ."&nbsp". $rows['lastname'] .",". "&nbsp". $rows['firstname'] ?>"> <?php echo $rows['lastname'] ?>,
<?php echo $rows['firstname'] ?>
- <?php
echo $rows['party_name']?></option>
Here's the preview.php:
<?php
$resultasa = $db->prepare("SELECT * FROM candposition");
$resultasa->execute();
for($i=0; $rowasa = $resultasa->fetch(); $i++){
$exrxrxrx=$rowasa['pos_name'];
if ($exrxrxrx!='Error') {
?>
<h2 class="fs-title"><?php echo $exrxrxrx ?></h2>
//this is the part where I call the value and also the codes of my example image
<input type="hidden" value="<?php echo explode("#", $_POST[$exrxrxrx])[0] ?>" name="votes[]" /><?php echo explode("#", $_POST[$exrxrxrx])[0] ?><br>

You can use the data attrbute in HTML5 to store the id.
Example:
<span data-id="<?= $id?>"><?= $firstname?> <?= $lastname?></span>

Related

Select a checkbox by default

I know that this question has been asked before, but I am struggling with selecting a default checkbox. I want the checkbox to be "Kenyan Used" by default as in the picture below:Selected "Kenyan Used. What i have tried is $taxonomy= $wpdb->get_results("SELECT term_id FROM par_taxonomy WHERE (taxonomy = 'condition' AND term_taxonomy_id= '181')");. Though I don't how the below code implements this, I know it is a for loop, but how do i modify it to work for my case?. Below is the specific code from where the taxonomies are fetched from:
<?php
if (!empty($modern_filter)){ $counter = 0;
foreach ($modern_filter as $modern_filter_unit) {
$counter++;
$terms = get_terms(array($modern_filter_unit['slug']), $args);
if (empty($modern_filter_unit['slider']) && $modern_filter_unit['slug'] != 'price') { /*<!--If its not price-->*/
//if ($modern_filter_unit['slug'] != 'price') { /* != 'price'<!--If its not price-->*/
/*First one if ts not image goes on another view*/
if ($counter == 1 and empty($modern_filter_unit['use_on_car_modern_filter_view_images'])
and !$modern_filter_unit['use_on_car_modern_filter_view_images']) {
if (!empty($terms)) { ?>
<div class="stm-accordion-single-unit <?php echo esc_attr($modern_filter_unit['slug']); ?>">
<a class="title" data-toggle="collapse"
href="#<?php echo esc_attr($modern_filter_unit['slug']) ?>" aria-expanded="true">
<h5><?php esc_html_e($modern_filter_unit['single_name'], 'motors'); ?></h5>
<span class="minus"></span>
</a>
<div class="stm-accordion-content">
<div class="collapse in content" id="<?php echo esc_attr($modern_filter_unit['slug']); ?>">
<div class="stm-accordion-content-wrapper">
<?php foreach ($terms as $term): ?>
<?php if (!empty($_GET[$modern_filter_unit['slug']]) and $_GET[$modern_filter_unit['slug']] == $term->slug) { ?>
<script type="text/javascript">
jQuery(window).load(function () {
var $ = jQuery;
$('input[name="<?php echo esc_attr($term->slug . '-' . $term->term_id); ?>"]').click();
$.uniform.update();
});
</script>
<?php } ?>
<div class="stm-single-unit">
<label>
<input type="checkbox"
name="<?php echo esc_attr($term->slug . '-' . $term->term_id); ?>"
data-name="<?php echo esc_attr($term->name); ?>"
/>
<?php echo esc_attr($term->name); ?>
</label>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
<?php } ?>
Thanks for the help in advance.
Assuming that this is the checkbox you want to do this for: Add an if statement to determine if the checkbox should be checked by default
<input type="checkbox"
name="<?php echo esc_attr($term->slug . '-' . $term->term_id); ?>"
data-name="<?php echo esc_attr($term->name); ?>"
<?php if($condition){?> checked <?php } ?>
/>
Replace $condition with something to determine if this is the checkbox you want checked by default. If you want all checkbox checked by default just add 'checked' inside the input tag without any if statements.
You need to add the checked attribute to your checkbox. You can check for the required term with an if statement. You need to add the following:
<?php if ($term->name == 'Kenyan Used') { echo ' checked'; } ?>
So then your input code looks like this:
<input type="checkbox"
name="<?php echo esc_attr($term->slug . '-' . $term->term_id); ?>"
data-name="<?php echo esc_attr($term->name); ?>"
<?php if ($term->name == 'Kenyan Used') { echo ' checked'; } ?> />
<?php echo esc_attr($term->name); ?>
Hope this helps!

Data from database show/hide onclick trouble

<?php
$getNews = $db->prepare("SELECT * FROM news ORDER BY id DESC LIMIT 4");
$getNews->execute();
$news = $getNews->fetchAll();
foreach ($news as $newspost) {
echo $newspost['title'] ; ?> <a style="cursor:pointer;" onclick="return toggleMe('problem')">read/hide</a>
<?php
echo '<br />';
echo 'Posted by '; echo $newspost["user"]; echo ' at '; echo $newspost["created"]; ?>
<div id="<?php echo $newspost['id']; ?>" style="display:none;">
<?php
echo $newspost['message'];
?>
</div>
<?php
echo '<br /> <br />';
}
?>
What I had in mind was that it shows/hides the text from the newspost when you hit the read/hide link next to the title of the newspost.
I can fit the $newspost['id'] in the representing div but because the onclick="return toggleMe('problem')"> has both " and ' in it I need another way to fit it in there, I searched a lot but couldn't find what I was exactly looking for.
Actually, you'll be fine with:
"return toggleMe('<?php echo $newspost['id']; ?>');"
The inner single quotes will never be seen in the output HTML, and the <?php ?> block doesn't care what quotes surround it.

How to get the ID of the link in another page in php

I like to catch the id of below tag in show.php file
once the link is clicked... I have already got the href name in show.php
<?php
if (isset($_GET['submit'])) {
$choice=$_GET['prod'];
$dbc=mysqli_connect('localhost','root','','online_shopping') or die('Connection Error');
$query1="SELECT name, id from ".$choice; $result1=mysqli_query($dbc,$query1) or die('Error querying Database');
echo "<h1>List of available products in your category</h1><hr>";
while($row = mysqli_fetch_array($result1)) {
$id=$row['id'];
?>
<a style="font-size:18px; text-decoration:none; text-align:center; color:#09F;" href="show.php?ref=<?php echo $row['name'];?>" id="<?php echo $id;?>"><?php echo $id;echo '.'.$row['name']; echo '</a>';
The id attribute is only used client side, so short of using JavaScript to modify the URL — you can't.
Put the data in the URL in the first place … and exercise some safety over adding data to URLs and HTML.
<a href="show.php?ref=<?php
echo htmlspecialchars(urlencode($row['name']));
?>&id=<?php
echo htmlspecialchars(urlencode($id));
?>"
id="<?php
echo htmlspecialchars($id);
?>"><?php
echo htmlspecialchars($id) . '.' . htmlspecialchars($row['name']);
?></a>
I believe you're looking for $_GET.
<?php
//show.php?ref=5&id=10
echo $_GET['ref'];
//5
echo $_GET['id'];
//10
?>
<?php echo $_GET["id"]; ?>

PHP: Print contents of MySQL table, each row in it's own div

I have a table in MySQL with 5 rows (filename, location, type, author, date) and I would like to use PHP to print something like the following:
<div id="file">
(filename) - (author)<br>
(type) - (date)
</div>
I would like a new div to be created for every row in the table, is this possible?
<?php
while($row = mysql_fetch_assoc($result)){
echo '<div id="file">'.$row['filename'].' - a '.$row['author'].'<br>
'.$row['type'].' - '.$row['date'];
}
you need to iterate like so:
<?php $result = mysql_query('SELECT * FROM files;') ?>
<?php while($row = mysql_fetch_assoc($result)) : ?>
<div id="file">
<a href="<?php echo $row['location'] ?>">
<?php echo $row['filename'] ?>
</a>
- <?php echo $row['author'] ?>
<br>
<?php echo $row['type'] ?> - <?php echo $row['date'] ?>
</div>
<?php endwhile ?>

Dynamically populating an UnOrdered List

I am attempting following code to populate an UnOrdered List dynamically. The same type of code I am successfully using to populate a DropDown. But when I changed the tags to UnOrdered List, it is not working. When run, it just displays some tags instead of the actual output.
Where is the error:
<?php
require("dbconnection.php");
require("dbaccess.php");
$divName = $_GET['DivName'];
$ulName = $_GET['ControlName'];
$query = $_GET['SqlQuery'];
echo $query;exit;
dbconnection::OpenConnection();
$result = dbaccess::GetRows($query);
?>
<ul id="<?php echo $ulName; ?>" name="<?php echo $ulName; ?>">
<?php while($row=mysql_fetch_array($result))
{ ?>
<li><?php echo $row[1]; ?>"></li>
<?php } ?>
</ul>
The code that I used to populate a DropDown is below: It works absolutely fine:
<?php
require("dbconnection.php");
require("dbaccess.php");
$dropdownControlName = $_GET['DropDownControlName'];
$query = $_GET['SqlQuery'];
dbconnection::OpenConnection();
$result = dbaccess::GetRows($query);
?>
<select id="<?php echo $dropdownControlName; ?>" name="<?php echo $dropdownControlName; ?>">
<option>Select from the list</option>
<?php while($row=mysql_fetch_array($result))
{ ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
<?php } ?>
</select>
The error is here:
<li><?php echo $row[1]; ?>"></li>
should be this:
<li><?php echo $row[1]; ?></li>
Don't know Php but what this line doing :
echo $query;exit;
Are you sure that you have to use the second field of the result set?
<li><?php echo $row[1]; ?>"></li>
There is an extra >" there.
Can you show us the resulting html code ?
SORRY: I was away from the PC for some minutes before posting, just saw that I answered the same as the following answer.
HI,
I used your code and gave some constant values and i got the following out put.
Out Put:
1">
2">
3">
4">
Used code:
`
">
`
and final Conclusion is, this prints the unordered list and i think yo may check your
echo $row[1]; part for any html out puts.
Note: "> This tag comes because of in your code having this value

Categories