I want to code a script that will echo an amount of images based on the mysql_num_rows(); function.
Like, I'm storing 3 in a row. Then I'll create:
$images = mysql_num_rows($count);
Then I would like it to echo 3 images.
Is this possible?
If you don't get the question or want me to rewrite it, please just tell me.
Then i think, all you need to do is fetch the rating (i.e. a number) from the database and just use that number directly to display the number of stars. Coz mysql_rows_count would give you the total number of records in a result set which is returned as a result of a select query on multiple columns, but in your case you only need to access one column which would contain the rating and another column which would probably contain user id or some sort of key to associate the ratings with. The result set can be fetched as an associative array which can then be used by indices to fetch the right column. Have a look at this: PHP-mysql_fetch_array() .
EDIT: just to sum up (not the actual syntax) :
$array = mysql_fetch_array(<your select query fetching only the needed columns>);
$images = $array[0] // assuming the rating number is at the 0th index
//image display code, do your stuff
So here is what I did:
I had the numbers from 1-5 in my database in a row called 'rating'. Now when I picked this out of the database I stuffed the number (1-5) into a variable called '$starRating'.
for($i=1;$i<=$starRating;$i++){
echo "<span class='star'><span class='starText'>$i</span></span>";
}
Then I created a class called star and starText:
.star{
width:18px;
height:18px;
background:url('../images/design/smallImg/star.png') no-repeat;
text-align:center;
float:right;
margin-top:2px;
}
/* star content */
.starText{
display:none;
}
.starText is made to hide the text that would've been from the for() loop.
* I don't know if you can avoid the text another way around *
This works for me perfectly.
I wrote this to help people searching for an easy solution to this.
Related
Please can somebody be so kind to show me the syntax for using cloneblock in phpword.
So Ive got data in a MySQL DB, and for the single rows that I need to import into my word doc via phpword it works fine....to run my query and search and replace with template processor. BUT, now I want to insert multiple rows into my word document. I've researched and found that the cloneblock method is the answer. However I cannot get it working....currently my code runs but it doesn't seem to get to the second row.
I actually dnt get any error messages. My code executes fine...but the end display word file doesn't display fine....and if you see my code I got an echo statement...which echo's out in my browser exactly what I want "damaged" &"good", (as an example given of one of the row data) but that data doesn't get pulled into my word doc like that...it duplicates "damaged" , "damaged". .
$group_key=1;
do {
//loop to increase my uuid - ($repeatgroup')
$repeatgroup = $id."/"."trailer_repeat_group"."[".$group_key."]";
// query string
$trailer_repeat_grouping = mysqli_query($connect, "SELECT * FROM trailer_repeat_group LEFT JOIN main on trailer_repeat_group.PARENT_KEY = main.metainstanceID WHERE trailer_repeat_group.KEY_id = '$repeatgroup'");
$templateProcessor->cloneBlock('CLONEME', $trailer_count);
while ($row1 = mysqli_fetch_array($trailer_repeat_grouping)) {
//this echo below I am using to test exactly what happends – independent of
//PHPword/templateprocessor
echo $rttc = $row1['right_trailer_tyre_condition'];
//inserting / searching / inserting values
$templateProcessor->setValue("right_trailer_tyre_condition", $rttc);
}
// ending of loop / checking loop
$group_key++;
} while ($group_key <= $trailer_count);
I've done investigation and found the solution.
You're cloning same blocks N times:
$templateProcessor->cloneBlock('CLONEME', $trailer_count);
and then by doing fetch You're trying to replace right_trailer_tyre_condition with some value:
$templateProcessor->setValue("right_trailer_tyre_condition", $rttc);
Issue is that You're replacing all placeholders.
But in fact You need to replace them one by one with different values.
Solution is to define 3rd argument that means count of items to replace.
Simply change it to be:
$templateProcessor->setValue("right_trailer_tyre_condition", $rttc, 1);
I have a csv file which contain two columns
first column with Part number and second one is Image Name (Multiple Image for each product and Image Name based on Part Number )
I want to check each Part number with entire second column of Image Name each time as this is not sorted properly and store that image name for that perticuler part number in another csv along with that part number.
Current CSV
PartNumber Image Name
WP35001153 35001153R.jpg
WPW10135901 35001153R_Back.jpg
WPW10184873 W10135901R.jpg
WPW10200900 W10135901R_BACK.jpg
WPW10215493 W10137702R.jpg
WPW10249237 W10137702R_Back.jpg
WPW10258402 W10141364R.jpg
WPW10477076 W10477076R.jpg
WP8194064 W10477076R_Back.jpg
W10479760R.jpg
As above csv Part one WP35001153 have two images in on right side 35001153R.jpg and 35001153R_Back.jpg
Also Part number column and Image Column is not perticulary or properly assigned.
So I want to search Part Number with Image name entrie column and if it matches then store in Image1 Column and more than two times it should be store in next column Image2 like below.
PartNumber Image1 Image2
WP35001153 35001153R.jpg 35001153R_Back.jpg
WPW10135901 W10135901R.jpg W10135901R_BACK.jpg
WPW10200900 W10200900.jpg
Please help to figure it out
Thanks
Seem you need to build a new array, using your first column (of csv), cleaned as a key and add to it all you find related too.
Exemple (not exact code)
$mynewarray = [];
foreach ($mycsv as $line) {
$id = $line['PartNumber'];
if ($id[2] == 'W') {
it's a key, clean to obtain : 35001153
mynewarray[$id] = ['pics'=>[ ... ]];
} else {
it's a pic, add the image name
clean the id image name to obtain the key 35001153
mynewarray[$id]['pics'][] = the pics;
}
}
If i understand well your need, this is the idea can solve your problem in one loop with few id analyze.
:) enjoy
I'm working in the IT department of my company and it is my responsibility to send daily reports of the calls registered in the Call Center department. I'm new with MySQL, PHP or HTML and I'm already facing my first problems.
My objective is to run some queries in PHP and then output them in a HTML table cell. Let me be more specific. I have access to a telephone record database and I need to count the number of total calls and lost calls of every branch daily. Right now I just run 2 queries in MySQL and then copy-paste them in a .xls table.
I have the right queries, I get the right result in mysql, even in PHP I get the result posted on the webpage (kind of), but I don't know how to create a table, or how to input the result of a query into a specific cell of the table.
Here's what I've got so far:
<?php
$conn=#mysql_connect('host', 'username', 'password', 'asteriskcdrdb.cdr');
echo ('total calls ROPCW: ');
$result=mysql_query('select count(*) from asteriskcdrdb.cdr where calldate like "2016-04-11%" and dst="020" and disposition="ANSWERED" and duration > "10" ');
echo mysql_result($result, 0);
mysql_close($conn);
?>
This code will post on my page the count of total calls made on 4.11.2016 like this:
total calls ROPCW: 369
My objective is to create a table like this:
So the result of that query I mentioned above would go on the ROPCW->Total cell (where is 305) on the left side, on the right side are the monthly reports so far.
You can work out one big query or use a view to gather the data you need from a single source. Other suggestion would be, looping through all your branches and gather all the data you need, to build an associative array indexed similar to this:
$records[branch] = [date => [total => x, lost => y], mtd => [total => X, lost => Y]];
Then just do a:
foreach ($records as $branch => $record)
{
echo string to build table row
}
I suggest use mysql_fetch_object or mysql_fetch_assoc functions instead of mysql_result. Basically because those functions fetch an entire row instead of one single cell value. For your example query works fine because your aggregate function returns only one cell and row. But for your desired output won't work.
Keep in mind that you can inject HTML code within PHP and vice versa. Just do something like:
The idea would be run a select * from yourTable;
Then,
$result = mysql_query($sql);
echo "<table>\n";
echo "<tr><th>Branch</th></tr>\n";
while ($callRecord = mysql_fetch_object($result)) {
echo "<tr><td>{$callRecord->branch}</td></tr>\n";
}
echo "</tr>\n";
echo "</table>\n";
That should output a list of all tour branches. this is a guideline.
Hope this helps!!
You can go to www.php.net and choose between mysql_fetch functions which one will work better for you.
I have to make an array with the POSTED value of one SELECT. The SELECT selects the products ONE BY ONE. First I choose one product and POST it then another product and I POST the SECOND ONE and so on.....
I want to create an array of the ID of the products that are posted by the SELECT but this array has to grow while I introduce more and more products.
I have use this but It makes the array with only the last product I have choosen.
foreach($_POST['idproducto'] as $key => $val) {
$cadenaides = $cadenaides . "$val,";
}
$cadenaides = $cadenaides . 1;
I would like the array to have all the ID of the products I choose ONE BY ONE in the SELECT.
Seems to me like you want to assign a number to each posted value. You can do this like so:
foreach(...) {
$cadenaides[] = $val;
}
Your values will the be stored in an array. You can check your array with print_r($cadenaides);.
Reading the comments above and assuming that you use MySQL I would suggest the following:
SELECT GROUP_CONCAT(id_producto SEPARATOR ',') FROM producto WHERE .... put your conditions here ..;
This will concatinate all IDs in a single string like that 1,2,3,5,8,9... in a single result, after that you can do just one POST request. Very usefull in many cases BTW.
The result is truncated to the maximum length that is given by the group_concat_max_len system variable, which has a default value of 1024. Could be very large - max: 4294967295 for 32-bit system.
A php custom function returns record set from a mysql query.
I need to populate a two column table having equal quantity or balanced between two.
I know we can split by number of columns the row count then use a loop to populate each td accordingly.
Any suggestions or most practical way to display record sets onto tables organized according to their sizes?
Not using templates at this time.
Basically need to control the TD tag from been echo or not and filled.
Sample Code:
$col_num = 2; //Number of colums to parse data onto.
$count_r = mysql_num_rows($result)/$col_num;
echo '<table style="width:400px;border:3px solid green;"><tr><td>';
$ui=1;
while($row = mysql_fetch_array($result))
{
if($ui<$count_r)
{
echo '<input disabled type="checkbox" value="$row[id]"'; $this->ischecked($uid,$row[id]); echo "/>".$row['name'].'<br>'."\r\n";
}
$ui++;
}
//FIRST COLUMN SET
echo '</td>';
echo '<td>';
//SECOND COLUMN SET
echo '</td></tr></table>';
If you don't mind about the order of your records you could simply do (assuming you've got your results in an array called $result) the following:
...
echo "<table>";
for($i=0;$i<count($result);$i+=2):
echo "<tr>";
echo "<td>{$result[$i]['field']}</td>";
echo "<td>{$result[$i+1]['field']}</td>";
echo "</tr>";
endfor;
echo "</table>";
I don't know if it's the best way of doing this but it's the way I'd do it in your case. Keep in mind that I'm not checking if there are any actual results, we are assuming that it's the case. To check if $results is set you could use an if statement checking it's count number for example.
Note
Replace for($i=0;$i<count($result);$i+=2): with for($i=0;$i<count($result);$i+=2){ and endfor; with } for a traditionally formatted code.
I'd recommend using an unordered list -- <ul>, and apply the CSS float attribute to its list items (<li>). That way, you won't have to worry about counting the number of records.
Just output each record in a <li>, and set them all to float: left;.
Then constrain the height of the <ul> so it will be short enough to force the extra <li>s to float to a new column.
As #Steve pointed out, you'll also need to set the <li> width to be constant so the columns will be consistent. And make the width of your <ul> more than twice and less than three times as big as the <li> width.
A basic way to do that would be to call mysql_num_rows() on your query. Multiply the result by the height of each <li>, then divide by two, and that will be the height of your <ul>. That will make each column of equal height.
You could also do it with <div>s (one <div> for each item, all wrapped in a single global <div>).
But using a list is the preferred way of displaying a list of information in HTML (unless the information is tabular in nature and requires multiple columns per field, which yours isn't and doesn't).
If you need more detailed help, there's a great Opera Web Standards article on this.