sayedsohail Posted November 26, 2007 Share Posted November 26, 2007 Hi everyone, I had to print decription on a pre-printed form against items in a serial number on a specific postion i.e, Pre-printe form Serial Number Description 1.1 if($row['title']=='1.1'){ echo "$row['description']";} 1.2 if($row['title']=='1.2'){ echo "$row['description']";} 2.1 if($row['title']=='2.1'){ echo "$row['description']";} 2.1 if($row['title']=='2.2'){ echo "$row['description']";} 3.1 if($row['title']=='3.1'){ echo "$row['description']";} 3.2 if($row['title']=='3.2'){ echo "$row['description']";} 4.1 if($row['title']=='4.1'){ echo "$row['description']";} 4.2 if($row['title']=='4.2'){ echo "$row['description']";} Can someone suggest any better method than this. Please advise. Thanks, Link to comment https://forums.phpfreaks.com/topic/78965-printing-issue/ Share on other sites More sharing options...
pocobueno1388 Posted November 26, 2007 Share Posted November 26, 2007 Well...you are using more if statements than you need to, you only need one since you are doing the same thing for each one. <?php if ($row['title'] == '1.1' || $row['title'] == '1.2' || $row['title'] == '2.1' || $row['title'] == '2.2' || ...and so on){ echo $row['description']; } ?> Link to comment https://forums.phpfreaks.com/topic/78965-printing-issue/#findComment-399605 Share on other sites More sharing options...
sayedsohail Posted November 26, 2007 Author Share Posted November 26, 2007 thanks the problem is if 1.1 it has to print on row 1 and column 10 on the form. and if 4.1 than it has to print on row 7 and columen 10. I am just struggling to figure out how to achieve this. thanks anyway. Link to comment https://forums.phpfreaks.com/topic/78965-printing-issue/#findComment-399611 Share on other sites More sharing options...
pocobueno1388 Posted November 26, 2007 Share Posted November 26, 2007 Is there some sort of pattern to the numbers to where they should display? I don't understand how you got 4.1 should be printed on row 7 col 10. Link to comment https://forums.phpfreaks.com/topic/78965-printing-issue/#findComment-399621 Share on other sites More sharing options...
sayedsohail Posted November 26, 2007 Author Share Posted November 26, 2007 yes there is a pattern, titles in sequential order an the description should print against this order. the $row['title'] and $row['descriptiion']. But it is not necessary that data comes in sequential order, therefore i need to use if statment to see if there is any matching titles and than print on specific location row 1 to row 50 so on. 1.1 1.2 1.3 1.4 1.5 2.1 2.2 2.3 2.4 2.5 3.1 3.2 3.3 3.4 3.5 4.1 4.2 4.3 4.4 4.5 Thanks, Link to comment https://forums.phpfreaks.com/topic/78965-printing-issue/#findComment-399626 Share on other sites More sharing options...
xyn Posted November 26, 2007 Share Posted November 26, 2007 Can you show me the table your using. i know a solution but seeing your table will help. Regards. Link to comment https://forums.phpfreaks.com/topic/78965-printing-issue/#findComment-399627 Share on other sites More sharing options...
sayedsohail Posted November 26, 2007 Author Share Posted November 26, 2007 the table structure is: id autoincrement title varchar 10 description varchar 50 Link to comment https://forums.phpfreaks.com/topic/78965-printing-issue/#findComment-399629 Share on other sites More sharing options...
xyn Posted November 26, 2007 Share Posted November 26, 2007 i mean the one your trying to display the data on. if you're using a html table? Link to comment https://forums.phpfreaks.com/topic/78965-printing-issue/#findComment-399631 Share on other sites More sharing options...
sayedsohail Posted November 26, 2007 Author Share Posted November 26, 2007 this is the output of html table Serial Number Description 1.1 xyz 1.2 2.1 2.1 3.1 3.2 4.1 4.2 so on. Link to comment https://forums.phpfreaks.com/topic/78965-printing-issue/#findComment-399633 Share on other sites More sharing options...
xyn Posted November 26, 2007 Share Posted November 26, 2007 kk well in your description on the HTML bit. put this {1.1} then in the php use preg_replace("{1.1}",$row[description],$form); Link to comment https://forums.phpfreaks.com/topic/78965-printing-issue/#findComment-399636 Share on other sites More sharing options...
sayedsohail Posted November 26, 2007 Author Share Posted November 26, 2007 well thanks for that, but i got 1.1 to 50.1 than in that case i had to write 50 times (preg_replace("{1.1}",$row[description],$form); ) which is same as using echo and if statement. Link to comment https://forums.phpfreaks.com/topic/78965-printing-issue/#findComment-399649 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.