Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, is it possible to display to rows when MySQL value=2?

For Example: value=2 then Row1=Test1234, Row2=Test1234

Thanks!

Edit:

PHP
<pre><?php
require_once("DBController.php");
$db_handle = new DBController();
$result = $db_handle->runQuery("SELECT * FROM toy");
$header = $db_handle->runQuery("SELECT `COLUMN_NAME` 
FROM `INFORMATION_SCHEMA`.`COLUMNS` 
WHERE `TABLE_SCHEMA`='blog_samples' 
    AND `TABLE_NAME`='toy'");

require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',12);		
foreach($header as $heading) {
	foreach($heading as $column_heading)
		$pdf->Cell(90,12,$column_heading,1);
}
foreach($result as $row) {
	$pdf->SetFont('Arial','',12);	
	$pdf->Ln();
	foreach($row as $column)
		$pdf->Cell(90,12,$column,1);
}
$pdf->Output();
?>


That is the basic code.
The Database entry looks like this:
name=test1234
value=2

if value=2 i want to display this row twice. If value=1 i want to display the data only once.

What I have tried:

I tried to search for this in google but I dont found any soloution.
Posted
Updated 7-Jun-20 6:34am
v3
Comments
Richard MacCutchan 30-May-20 5:48am    
Your question is not clear; please add more details, especially explain what is not working.
Fynn Pfingsten 30-May-20 5:57am    
Done!
Richard MacCutchan 30-May-20 7:07am    
Just use it as another loop variable to repeat a row. But I cannot see where the value variable gets set.
Fynn Pfingsten 30-May-20 7:26am    
Thanks! Yes because i dont know how to do, can you help me please?
Richard MacCutchan 30-May-20 8:11am    
OK. Where is the value variable? I do not see any mention of it in your code. Where is the code that is trying to display this data?

1 solution

Is this what you mean?

PHP
if ($row['4'] == "2") {
			
 echo "" . $row["1"] . "" . $row["1"]. "";
}
else if ($row['4'] == "3") {	

 echo "" . $row["1"] . "" . $row["1"]. "". $row["1"]. "";
} 
else {

 echo "" . $row["1"] . "";	
				
}
 
Share this answer
 
v2
Comments
Maciej Los 26-Jun-20 3:10am    
This version:
var count = $row[4];for (i = 0; i < count; i++) {  echo $row[1]." ";}

is more adequate ;)
Richard MacCutchan 26-Jun-20 3:16am    
Yes, as in my comment the following day. I really cannot remember what this was all about. :(
Maciej Los 26-Jun-20 3:27am    
I think that the modesty inside you is taking...
Seems, you've guessed what OP is trying to achieve...
Cheers!
Maciej
Richard MacCutchan 26-Jun-20 3:57am    
Oh I know that. It's just that i can't remember how I got the answer. :)
Maciej Los 26-Jun-20 4:17am    
Well... In such of cases, we call that phenomena in Poland: "pomroczność jasna". (BTW: Lech Walesa - ex. polish president use it for the first time) I'm pretty sure there's no direct translation. I think it might be: 1) "momentary laps in judgment", 2) "blind-drunk". The second one is more about original meaning... Some times some words, some ideas, thoughts come to our brains with no reason...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900