Php echo three different css formats - php

I am trying to add three different css formats to data pulled from MySQL database.
I have formatted the first row fine but I cant get the other two working at all,
any ideas what I am doing wrong?
//run the query
$loop = mysql_query("SELECT * FROM employee")
or die (mysql_error());
while ($row = mysql_fetch_array($loop))
{
echo "<p style='color:#0000ff; font-size:22px'>".$row ['employee_name']."</p>" "<p style='color:#00000f; font-size:32px'>".$row['employee_id'] . "</p>" "<p style='color:#000000; font-size:42px'>". $row['employee_contact'] . " </p>" . "<br/>";
}

You have an unecessary gap:
$row['employee_id'] . "</p>" "<p style='color:#000000; font-size:42px'>"
^^^^^
here
Either get rid of the quotes or add a concatenation operator.
$row['employee_id'] . "</p> <p style='color:#000000; font-size:42px'>"

Your quotes are not balanced. Try this :
echo "<p style='color:#0000ff; font-size:22px'>".$row ['employee_name']."</p> <p style='color:#00000f; font-size:32px'>".$row['employee_id'] . "</p><p style='color:#000000; font-size:42px'>". $row['employee_contact'] . " </p> <br/>";

Related

How to add Microdata attributes in PHP

I use Microdata attributes in HTML code.
How can I add Microdata attributes to the following tag (PHP)?
if (!empty($speciality)) {
echo "<p><strong>" . __('Speciality', 'framework') . "</strong><span>" . $speciality . "</span></p>";}
The page will not load when I enter the following way :
echo "<p itemscope itemtype="https://schema.org/medicalSpecialty"><strong>" . __('Speciality', 'framework') . "</strong><span itemprop="medicalSpecialty" >" . $speciality . "</span></p>";
you are using double quotes in a double quotes which is wrong, use backslash or single quote when you need.
Try This code
echo "<p itemscope itemtype='https://schema.org/medicalSpecialty'><strong>" . __('Speciality', 'framework') . "</strong><span itemprop='medicalSpecialty' >" . $speciality . "</span></p>";
You're mixing single and double quotes but you need to reserve either single or double quotes to escape the string so that your PHP isn't read as HTML when echoed. The below snippet will work without any errors:
if (!empty($speciality)) {
echo "<p itemscope itemtype='https://schema.org/medicalSpecialty'><strong>'".
__('Speciality', 'framework') . "'</strong><span itemprop='medicalSpecialty'
>'" . $speciality . "'</span></p>";
}

Some html tags' parameters messup html/php code

When I create/edit post to my website, and when I use html tags (either type it by my self or using WYSIWYG editor (in this case nicEdit, but I've used different one - same problem)) it does not show anything on the page.
to be more specific: I have article container which imports php code, which than iterates through the db table and echo posts. This is the code:
<h3>Wydarzenia</h3>
<?php
//collects data from table "events" and sort it by "id" date in descending oreder
$event_table_data = mysqli_query($db_con, "SELECT * FROM events ORDER BY id DESC")
or die(mysqli_error());
//puts the data from "events" into an array
$event_content_array = mysqli_fetch_array($event_table_data);
//makes variables from table columns
$id = id;
$title = title;
$happeninng_date = happen;
$created_date = created;
$content = content;
$author = author;
//add new post button
if((isset($_SESSION['sess_wizardrights'])) && ($_SESSION['sess_wizardrights'] == true)){
echo "<a class='e_event_addpost_link' href='./index.php?link=add_post'><button class='e_event_addpost_button' type='button'>Dodaj nowy post</button></a>";
}
do{
//echo each event for main event article
echo "<span class='b_events_span' id='" . $event_content_array[$id] . "'>";
echo " <a class='b_events_anchor' id='" . $event_content_array[$id] . "'></a>";
echo " <h2 class='b_events_title'>" . $event_content_array[$title] . "</h2>";
if((isset($_SESSION['sess_wizardrights'])) && ($_SESSION['sess_wizardrights'] == true)){
echo "<form class='b_events_edit_form' name='edit_post' action='./index.php?link=edit_post' method='post'>";
echo " <input type='hidden' name='id' value='" . $event_content_array[$id] . "'> ";
echo " <input class='e_events_edit_submit' type='submit' value='Edytuj wydarzenie'>";
echo "</form>";
}
echo " <div class='fb-share-button' data-href='http://www.zhppgkaberdeen.co.uk/index.php?link=events#" . $event_content_array[$id] . "'></div>";
echo " <p class='b_events_happening_date'><i>Data wydarzenia: " . $event_content_array[$happeninng_date] . "</i></p>";
echo " <p class='b_events_content'>" . $event_content_array[$content] . "</p>";
echo " <p class='b_events_created_date'>Utworzono: " . $event_content_array[$created_date] . "</p>";
echo " <p class='b_events_author'><b>Czuwaj!</b><br/>" . $event_content_array[$author] . "</p>";
echo "</span>";
}while($event_content_array = mysqli_fetch_array( $event_table_data ));
?>
When I add tags like <img> for instance with alt="" parameter it completely ruins web page. What I mean by that is that the article container is not shown at all (I've checked that with firebug) as well as everything after the article tag (like footer for instance). What is even more strange is that this: alt="text" did not break the page but every other random word does, how ever it does not show the "text" at image at all.
Similar thing happen when I tried to create table within the post and title or target parameter, I cant remember which one.
I have tried to use htmlentities($event_content_array[$content]), htmlspecialchar($event_content_array[$content]) and mysqli_real_escape_string($do_con, $event_content_array[$content]) -> non of this helped.
Is there a way to fix that or I just need to give up using this tags/parameters?
Thank you for any help or explanation
if you are using e.g echo "<img alt="text">";try to escape the " such as alt=\"text\"

php echo no output to display very puzzled, why?

I am getting no where with this, I am not getting any output from my echo ,can someone help, thanks in advance...singhy
code below...
$strSQL = "SELECT * FROM <tablename> WHERE id='" . $_GET["serviceName"] . "'";
$rs = mysql_query($strSQL);
while($row = mysql_fetch_array($rs)){
echo "<dt>Name:</dt><dd>" . $row["serviceType"] . " " . $row["serviceName"] . "</dd>";
echo "<dt>Phone:</dt><dd>" . $row["Phone"] . "</dd>";
echo "<dt>Birthdate:</dt><dd>" . $row["BirthDate"] . "</dd>";
}
// Close the database connection
mysql_close();
?>
<p>Return to the list</p>
</body>
</html>
can someone tell me where i am going wrong, ive tried various options, thanks in advance, singhy
Try this debugging code:
$serviceName = mysql_real_escape_string($_GET['serviceName']); // Read PS note at the end
$strSQL = "SELECT * FROM `tablename` WHERE id='$serviceName'";
$rs = mysql_query($strSQL) or die(mysql_error()); // Display any query error
echo "Total number of rows: ". mysql_num_rows($rs); // Echo number of rows
while($row = mysql_fetch_assoc($rs)){
echo "<dt>Name:</dt><dd>" . $row["serviceType"] . " " . $row["serviceName"] . "</dd>";
echo "<dt>Phone:</dt><dd>" . $row["Phone"] . "</dd>";
echo "<dt>Birthdate:</dt><dd>" . $row["BirthDate"] . "</dd>";
}
Please note
You should escape the $_GET request and never use it directly in a query statement. Use mysql_real_escape_string() for that. (This method will be deprecated, read next bullet)
many of the functions you are using will be deprecated starting php 5.5.0 Alternatively you can use PDO prepared statements
replace
$_GET["serviceName"]
with this
$_GET['serviceName']
use single quotes in $_GET in your case.

simple calculation of field for php mysql field

i have simple db that it is filled by a form from a page, all is ok in the entry.
i have 2 fields in the database are: all_students and current_students filled by the user in the form that i want to calculate
the trick is that i am echoing only the latest db record in the output page.. to give me only the latest data inserted in the form...
now, i want to create a new field that give me the absent students automatically (all - current)
what i have tried, i read that i can NOT create a new calculated field in the db, it is not an excel, so i am trying to echo the calculation results of these 2 fields, to a new value that is the "absent students"
what you suggest? please help, here is my code
<?php
$con=mysqli_connect("localhost","root","PasswordHere","DBnameHere");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT id, class, all_students, current_students FROM students ORDER BY id DESC LIMIT 1");
while($row = mysqli_fetch_array($result))
{
echo "Class: " . $row['class'] . "<br>";
echo "All students: " . $row['all_studnets'] . "<br>";
echo "Current students: " . $row['current_studnets'] . "<br>";
echo "Absent students: " . $row['all_studnets'] . - . $row['current_studnets'] . " <br>";
}
mysqli_close($con);
?>
You only put dot (.) if you want to concatenate a string. Please remove the dot since you are subtracting.
echo "Absent students: ";
echo floatval($row['all_studnets']) - floatval($row['current_studnets']);
echo "<br>";
Try this line
echo "Absent students: " . $row['all_studnets'] - $row['current_studnets'] . " <br>";
Insted of this
echo "Absent students: " . $row['all_studnets'] . - . $row['current_studnets'] . " <br>";

How to display comments inline

So I have this code (which works) that prints out the comments a user has just written. The issue im having is with displaying the comments. The username is displayed above the comment and I just want them to be displayed next to each other for example
'Username:'comment''
I have tried putting display:inline; in my CSS for h4 and p but it messes up everything else that i have put into these elements.
Does anyone know the answer?
This is my code
//Print out existing comment
$query = "SELECT * FROM comments JOIN users ON comments.userID = users.ID WHERE salonID=$salonid";
$result = mysqli_query($db_server, $query);
if (!$result) die("Database access failed: " . mysqli_error($db_server));
while ($row = mysqli_fetch_array($result)){
$str_comments .= "<div id='comments'><h4>" . $row['Username'] ."</h4><p>'" . $row['comment'] . "'</p>";
$str_comments .="<img src='" . $row['imagename'] ."' /></div>";
}
You put username inside <h4></h4> which is a block element. It's the same for <p></p>.
Block element will take a full row so you won't be able to place username & comment in a line.
You already give display:inline style for <h4></h4> & <p></p> it should be fine.
I encourage you to use a <span></span> instead which is an inline element by default.
Focus on this:
while ($row = mysqli_fetch_array($result)){
$str_comments .= "<div id='comments'>" .
"<span style='font-weigth:bold;'>" . $row['Username'] ."</span>" .
"<span>'" . $row['comment'] . "'</span>" .
"<img src='" . $row['imagename'] ."' />".
"</div>";
}
The easiest way to do it on your website is use annote ( http://annote.in ). A javascript based inline comment plugin. You can get started on any platform in minutes.

Categories